Rob*_*ert 7 php docker dockerfile docker-compose docker-image
我目前正在学习 Docker。阅读文档和几篇文章后,我显然有更多的问题而不是答案。目前对我来说最有趣的是:两者之间有什么区别?
FROM some:docker-image
Run Code Online (Sandbox Code Playgroud)
在 Dockerfile 和
image: digitalocean.com/php
Run Code Online (Sandbox Code Playgroud)
在 docker-compose.yml
我明白他们应该抓取图像并从中创建一个容器。我不明白的是如果我们同时指定两者会发生什么,例如:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml 和 Dockerfile 都指定了图像。当这些图像不同时会发生什么?docker-compose.yml 会永远赢吗?它会只使用这个“顶部”图像吗?它们会以某种方式重叠吗?或者,也许我都弄错了?
我确实看到了这一点,但我仍然不确定我是否理解发生了什么。
区别在于构建与运行
将图像视为应用程序,将容器视为运行应用程序的进程。运行应用程序不会更改应用程序。同样,运行容器不会更改图像。图像是通过Dockerfiles使用构建的docker build并且是持久的。容器是根据需要由 、kubernetes 或类似工具从镜像创建的docker run,docker-compose并且是临时的。
The Dockerfile is used by the docker build command to build a new image.
In the Dockerfile the first line usually specifies the base image with FROM, i.e. FROM nginx. Subsequent RUN lines in the Dockerfile provide the additional steps that docker build will execute in a shell, within the context of the FROM image, to create the new image. Note that the Dockerfile does not specify the name of the new image. Instead, the new image is named in the -t some/name option to docker build
The docker-compose.yml file specifies a group of images to download and run together as part of a combined service. For example, the docker-compose.yml for a blog could consist of a web server image, an application image, and a database image and would specify not only the images but also possibly how they communicate.
Since docker builds and docker compose are separate operations, there is no conflict or detection of differences. The docker-compose.yml controls what is going to be download and run, and you can also build whatever you like.
Also, as @David Maze mentioned in comments:
If you use both options then Docker Compose will build the image as specified and then tag it using the image: name; this can be confusing if you're putting a "standard" image name there.
我的猜测是,如果您这样做,您最终可能会得到一个与nginxDockerhub 镜像不匹配的镜像,比如在您自己的机器上。不要那样做。相反,请为您构建的任何映像使用唯一的名称。
| 归档时间: |
|
| 查看次数: |
1548 次 |
| 最近记录: |