Docker组成多个Dockerfile
我目前正在从事一个Maven项目,我想拥有2个Docker容器,一个在其中启动所有测试,另一个测试如果所有测试成功,则将编译该项目。
问题在于两个容器都会启动Prod Dodkerfile。
因此,我的问题是为什么将每个Dockerfile指向Docker中的每个Dockerfile之后,它们都始于Prod One
Docker-Compose.yml:
version: '3.8'
services:
db:
container_name: db
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: cuisine
MYSQL_ROOT_PASSWORD: example
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
ports:
- "3306:3306"
volumes:
- ./docker/mysql-dump/cuisine:/docker-entrypoint-initdb.d
- mysql:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
test:
container_name: java-test
image: spring-boot
build:
context: .
dockerfile: docker/test/Dockerfile
ports:
- "8081:8081"
- "5005:5005"
depends_on:
db:
condition: service_healthy
volumes:
- ${APPLICATION_ROOT_FOLDER}:/usr/src/mymaven
- ${MAVEN_SETTINGS_FOLDER}:/root/.m2
java:
container_name: java
image: spring-boot
build:
context: .
dockerfile: docker/prod/Dockerfile
ports:
- "8082:8082"
- "5006:5006"
depends_on:
db:
condition: service_healthy
volumes:
- ${APPLICATION_ROOT_FOLDER}:/usr/src/mymaven
- ${MAVEN_SETTINGS_FOLDER}:/root/.m2
volumes:
mysql:
I'm currently working on a maven project where I would like to have 2 docker container where one launch all the tests and the other compile the project if all the tests succeed.
The problem is that both containers launch the prod dockerfile.
So my question is why after pointing each Dockerfile in the docker compose they both start on the prod one
docker-compose.yml:
version: '3.8'
services:
db:
container_name: db
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: cuisine
MYSQL_ROOT_PASSWORD: example
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
ports:
- "3306:3306"
volumes:
- ./docker/mysql-dump/cuisine:/docker-entrypoint-initdb.d
- mysql:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
test:
container_name: java-test
image: spring-boot
build:
context: .
dockerfile: docker/test/Dockerfile
ports:
- "8081:8081"
- "5005:5005"
depends_on:
db:
condition: service_healthy
volumes:
- ${APPLICATION_ROOT_FOLDER}:/usr/src/mymaven
- ${MAVEN_SETTINGS_FOLDER}:/root/.m2
java:
container_name: java
image: spring-boot
build:
context: .
dockerfile: docker/prod/Dockerfile
ports:
- "8082:8082"
- "5006:5006"
depends_on:
db:
condition: service_healthy
volumes:
- ${APPLICATION_ROOT_FOLDER}:/usr/src/mymaven
- ${MAVEN_SETTINGS_FOLDER}:/root/.m2
volumes:
mysql:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您具有
构建:
和图像:
上的时,构建的图像用image:
name标记。您具有相同的映像:
两种服务的名称,因此要构建的最后一个wins''''''''''''''''''''''''''''''''''''''''''''''''wins'删除图像:
两者的名称。When you have both
build:
andimage:
on your services, the built image is tagged with theimage:
name. You have the sameimage:
name for both services, so the last one to be built 'wins' and is run for both services. Remove theimage:
name for both.