A base image is the image that is used to create all of your container images. Your base image can be an official Docker image, such as Centos, or you can modify an official Docker image to suit your needs, or you can create your own base image from scratch.
You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.
A Docker image has many layers, and each image includes everything needed to configure a container environment -- system libraries, tools, dependencies and other files. Some of the parts of an image include: Base image. The user can build this first layer entirely from scratch with the build command.
You can use it without doing anything special. If you have a local image called blah
you can do FROM blah
. If you do FROM blah
in your Dockerfile, but don't have a local image called blah
, then Docker will try to pull it from the registry.
In other words, if a Dockerfile does FROM ubuntu
, but you have a local image called ubuntu
different from the official one, your image will override it.
Verified: it works well in Docker 1.7.0.
Don't specify --pull=true
when running the docker build
command
From this thread on reference locally-built image using FROM at dockerfile:
If you want use the local image as the base image, pass without the option
--pull=true
--pull=true
will always attempt to pull a newer version of the image.
You can have - characters in your images. Assume you have a local image (not a local registry) named centos-base-image with tag 7.3.1611.
docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-common-1.12.6-16.el7.centos.x86_64
Go version: go1.7.4
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-common-1.12.6-16.el7.centos.x86_64
Go version: go1.7.4
docker images
REPOSITORY TAG
centos-base-image 7.3.1611
Dockerfile
FROM centos-base-image:7.3.1611
RUN yum -y install epel-release libaio bc flex
Result
Sending build context to Docker daemon 315.9 MB
Step 1 : FROM centos-base-image:7.3.1611
---> c4d84e86782e
Step 2 : RUN yum -y install epel-release libaio bc flex
---> Running in 36d8abd0dad9
...
In the example above FROM
is fetching your local image, you can provide additional instructions to fetch an image from your custom registry (e.g. FROM localhost:5000/my-image:with.tag
). See https://docs.docker.com/engine/reference/commandline/pull/#pull-from-a-different-registry and https://docs.docker.com/registry/#tldr
Finally, if your image is not being resolved when providing a name, try adding a tag to the image when you create it
This GitHub thread describes a similar issue of not finding local images by name.
By omitting a specific tag, docker will look for an image tagged "latest", so either create an image with the :latest tag, or change your FROM
For anyone who faces this issue in the future, where you have the image in your local but docker build
still tries to pull the image from docker hub, the problem might be that the architecture types are different.
You can check the architecture of the image using
docker inspect --format='{{.Os}}/{{.Architecture}}' IMAGE_NAME
Now in your Dockerfile
change FROM IMAGE_NAME
to something like FROM --platform=linux/amd64 IMAGE_NAME
and docker would now use the local image.
Remember to put not only the tag but also the repository in which that tag is, this way:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elixir 1.7-centos7_3 e15e6bf57262 20 hours ago 925MB
You should reference it this way:
elixir:1.7-centos7_3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With