Docker组成多个Dockerfile

发布于 2025-02-06 21:14:09 字数 1539 浏览 1 评论 0原文

我目前正在从事一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃扇骨 2025-02-13 21:14:09

当您具有构建:图像:上的时,构建的图像用image: name标记。您具有相同的映像:两种服务的名称,因此要构建的最后一个wins''''''''''''''''''''''''''''''''''''''''''''''''wins'删除图像:两者的名称。

When you have both build: and image: on your services, the built image is tagged with the image: name. You have the same image: name for both services, so the last one to be built 'wins' and is run for both services. Remove the image: name for both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文