Answer a question

I created docker-compose yaml file to run a docker image after it has been pulled locally and this yaml file contain another services (mysql and phpmyadmin) so when I run a command docker-composer up -d I found a conflict in creating a container as it been used by another container with the same name and I expected to show me that the container is already run and up to date, I know that the container must be removed or renamed before creating a new one but I aiming to get the newer version of image and check if mysql and phpmyadmin services is up or not if up gives me those container is up to date and if not create it as another environment bellow.

docker-compose.yml

version: '3.3'

services:
  app-prod:
    image: prod:1.0
    container_name: app-prod
    ports:
      - "81:80"
    links:
      - db-prod
    depends_on:
      - db-prod
      - phpmyadmin-prod

  db-prod:
    image: mysql:8
    container_name: db-prod
    environment:
      - MYSQL_ROOT_PASSWORD=secret
      - MYSQL_DATABASE=laravel
      - MYSQL_USER=user
      - MYSQL_PASSWORD=secret
    volumes:
      - db-prod:/var/lib/mysql

  phpmyadmin-prod:
    image: phpmyadmin/phpmyadmin:5.0.1
    restart: always
    environment:
      PMA_HOST: db-prod
    container_name: phpmyadmin-prod
    ports:
      - "5001:80"

volumes:
  db-prod:

Error

Creating phpmyadmin-prod ... error
Creating db-prod         ... 

ERROR: for phpmyadmin-prod  Cannot create container for service phpmyadmin: Conflict. The container name "/phpmyadmin-prod" is already in use by container "5a52b27b64f7302bccb1c3a0eaeca8a33b3dfee5f1a279f6a809695Creating db-prod         ... error

ERROR: for db-prod  Cannot create container for service db: Conflict. The container name "/db-prod" is already in use by container "5d01c21efafa757008d1b4dbcc8d09b4341ac1457a0ca526ee57873cd028cf2b". You have to remove (or rename) that container to be able to reuse that name.

ERROR: for phpmyadmin  Cannot create container for service phpmyadmin: Conflict. The container name "/phpmyadmin-prod" is already in use by container "5a52b27b64f7302bccb1c3a0eaeca8a33b3dfee5f1a279f6a809695f482500a9". You have to remove (or rename) that container to be able to reuse that name.

ERROR: for db  Cannot create container for service db: Conflict. The container name "/db-prod" is already in use by container "5d01c21efafa757008d1b4dbcc8d09b4341ac1457a0ca526ee57873cd028cf2b". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
Error: No such container: app-prod
Error: No such container: app-prod

While using another docker-compose file for test environment I got this which I expected

db-stage is up-to-date
phpmyadmin-stage is up-to-date
Creating app-stage ... done

Answers

As I have several docker-compose files and I run this command docker-composer -f <compose_file_path> -p <project_name> -d up and then I try to run docker-composer up -d in the same location without specify the project name -p <project_name> which gives me the conflict of the container as this make the compose-file up with a different project name and with the same container name.

Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐