Docker 命令之间的区别是什么: 运行、构建和创建

我看到有三个 docker命令似乎做着非常相似的事情:

  1. docker build
  2. docker create
  3. docker run

这些命令之间有什么区别?

43613 次浏览
  1. docker build . converts your Dockerfile into an image.
  2. docker create your-image creates a container from your image from step 1.
  3. docker start container_id starts the container from step 2.
  4. docker run image is a shortcut for 2. and 3. (docker create image and docker start container_id).

Here is the difference between image and container:

Image An image is a specified snapshot of your filesystem and includes the starting command of your container. An image occupies just disk-space, it does not occupy memory/cpu. To create an image you usually create instructions how to build that image in aDockerfile. FROM and RUN commands in the docker file create the file-snapshot. One may build an image from a docker file with docker build <dockerfile>

Container You can create new containers with an image. Each container has a file-snapshot which is based on the file-snapshot created by the image. If you start a container it will run the command you specified in your docker file CMD and will use part of your memory and cpu. You can start or stop a container. If you create a container, its not started by default. This means you can't communicate to the container via ports etc. You have to start it first. One may create an container from an image by docker create <image>. When a container has been created it shows the id in the terminal. One may start it with docker start <container_id>.