Two Docker containers of the same application.

Hello!
I’d like to have two docker containers of the same app, but with diff ports.
There are containers should use the same volumes.
I deploy using gitlab runner.

So, compose file:

version: "3.9"

volumes:
  static_volume:
    external: true
    name: static
  media_volume:
    external: true
    name: media

networks:
  reservation_net:
    external: true

services:
  api:
    image: app_image
    container_name: api
    build:
      context: ./
      dockerfile: ./docker/api/Dockerfile
    restart: always
    env_file:
      - .env
    volumes:
      - .:/api/
      - static_volume:/api/static
      - media_volume:/api/media
    networks:
      - reservation_net
    depends_on:
      - db

  api_2:
    image: app_image
    container_name: reservation_api_2
    build:
      context: ./
      dockerfile: ./docker/api_2/Dockerfile
    restart: always
    env_file:
      - .env
    volumes:
      - .:/api/
      - static_volume:/api/static
      - media_volume:/api/media
    networks:
      - reservation_net
    depends_on:
      - db

Runner file:

stages:
  - deploy
deploy_api:
  when: manual
  stage: deploy
  script:
   - sudo docker-compose -f compose-dev.yaml down api
    - sudo docker-compose -f compose-dev.yaml up -d --build api
  only:
    - Dev
  tags:
    - dev

deploy_api_2:
  when: manual
  stage: deploy
  script:
    - sudo docker-compose -f compose-dev.yaml down api_2
    - sudo docker-compose -f compose-dev.yaml up -d --build api_2
  only:
    - Dev
  tags:
    - dev

Problem:
When I start job by app everything is fine. Then I start job app_2. After that, my static and meida volumes in container with app unavailable.
When I do
docker exec -it app bash
then
ls -l api/media - empty.
But into container with app_2 - all ok.
If I repeat job 1 and recreate container 1 with app, volumes in that container available, but itno app_2 - not.
In general, whichever container starts last, there are volumes, but the previous one - empty.

Check /app/media vs /api/media.

1 Like

Sorry, I made a mistake in the description.
Of course I checked the api/media folder in the container.
And here is empty.

You have a spelling error, one time it’s app, one time it’s api. Is the mount correct, the folder correct which you check?