简体   繁体   中英

DockerFile: Is it use to create an image or To the docker host how to create the container

I am confused with some terms.

Is Dockerile designed to create an image or a set of instruction of how to create a container from an image?

Because there are command eg FROM (to get the base image), RUN (To run executable in the container) etc. These command looks like an instruction to how to create the container.

Docker images are static, and are built from the instructions specified in the Dockerfile . They use Union File-System (UnionFS), so that the changes made when building an image are stacked on top of each other, generating a DAG (Directed Acyclic Graph) of build history. The FROM directive at the top of the Dockerfile simply points to an existing image, and starts building on top of that.

A container is simply an instantiated version of an image, basically just this UnionFS with a read/write layer dropped on top of it.

Interestingly, if you watch the output when you run docker build (in a directory with a Dockerfile ) you'll see that what is happening is each instruction starts up a container based on the current state of the image, runs the command ( apt-get install ... or whatever) and then commit s that change to the image. That's why it's good to batch up commands in a Dockerfile - because each one will start a new container.

Dockerfile is used to create an image which you can later use to create a container using docker build .

From the docs

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Also RUN will instruction will execute any commands in a new layer on top of the current image and commit the results . The resulting committed image will be used for the next step in the Dockerfile and not "Run (To run executable in the container)". For details see this .

Image: Docker engine use Dockerfile reference to build up Image from Dockerfile instruction like (FROM, RUN etc.)

Container: Docker engine start container from Image and we can say Container is RUN time instance of Image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM