Random container names when creating from the same file

I have the following docker-compose.yml file:

 version: '2' services: php-apache: image: reynierpm/php55-dev ports: - "80:80" environment: PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE' volumes: - ~/data:/data 

Each time I run the following docker-compose up -d , it creates a container with the same name all the time, for example, php55devwork_php-apache_1 , which is the folder where the file is plus the service name. Example:

 [ rperez@dev php55-dev-work] $ tree . β”œβ”€β”€ composer.json β”œβ”€β”€ docker-compose.yml β”œβ”€β”€ Dockerfile 

Is there any way to change this name randomly? Now I want to test another application in one container, but another instance and the only solution I have is to copy the contents to another folder.

What would be the best solution?

+5
source share
2 answers

Since there is container_name: that you can add to your docker-compose.yml ( after PR 1711 ), one of the possible ways to solve the problem would be:

  • use the current docker-compose.yml as a template: copy it and add a random container name to the new container_name: xxx directive.
  • run docker compose up on this temporary docker-compose.yml .
+2
source

I don’t think you want random, you just want to change the name of the project.

You can change the name of the project with $PROJECT_NAME or -p

+2
source

Source: https://habr.com/ru/post/1258843/


All Articles