【发布时间】:2021-12-02 07:33:29
【问题描述】:
在查看How to name Dockerfiles 上的答案后,我还有很多问题。
就我而言,我至少需要两个Dockerfiles,一个docker-compose.yaml 和一个.dockerignore。听起来像使用 <purpose>.Dockerfile 或 Dockerfile.<purpose> 之类的扩展程序的缺点是失去了在 hub.docker.com 上使用 autobuilder 的功能。
所以其他人建议您将每个 Dockerfile 保存在一个目录中并从那里构建。
所以可能是这样的:
dockerfiles/
--python_consumer/
-----Dockerfile
--python_producer/
-----Dockerfile
--docker-compose.yaml
--.dockerignore
在这种情况下 .dockerignore 会在全局范围内适用于所有 dockerfile 吗?这种结构有什么大的缺点吗?
我的示例 docker-compose.yaml 没有单独的目录和一个组合的消费者/生产图像作为上下文。
version: '3.8'
services:
standalone:
hostname: standalone
container_name: standalone
image: apachepulsar/pulsar:2.8.1
ports:
- 8080:8080 # exposed would be a better practice
- 6650:6650 # exposed would be a better practice
command: bin/pulsar standalone
healthcheck:
test: ["CMD", "nc", "-vz", "localhost", "6650"]
interval: 20s
timeout: 5s
retries: 5
networks:
- conprod
conprod:
hostname: conprod
container_name: conprod
build:
context: .
dockerfile: ./Dockerfile
restart: on-failure # best practice is probably "unless-stopped"
depends_on:
- standalone
networks:
- conprod
networks:
conprod:
【问题讨论】:
-
docker-compose.yml是什么样的;子目录是否可用作独立的构建上下文?如果是这样,那么您应该将.dockerignore放在Dockerfiles 旁边。 -
我已经添加了我的
docker-compose.yaml以获取上下文。目前我的Dockerfile位于带有.dockerignore和docker-compose.yaml的根目录中。但是我需要两个Dockerfiles 来为两个不同的 python 应用程序构建两个容器。 -
.dockerignorefile 从build: { context: }目录中读取;它不会在其他任何地方产生影响。 -
所以要编辑以上内容,我的
context:将更改为./dockerfiles?
标签: docker docker-compose dockerfile naming-conventions