Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker compose multiple dockerfile

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 de 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading