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 command docker-compose up -d
it creates a container with the same name all the time as for example php55devwork_php-apache_1
which is the folder where the file is plus the service name. Ex:
[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 a different application in the same container but another instance and the only solution I have is to copy the content in another folder.
What would be the best solution?
However, if no name is provided by the user while creating/running a Docker container, Docker automatically assigns the container a name. If you look at them carefully, you could see a pattern emerge. The first name is an adjective while the second name is the surname of a notable scientist or hacker.
The docker-compose. yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).
Note: Container names must be unique. That means you can only call one container web . If you want to re-use a container name you must delete the old container (with docker container rm ) before you can create a new container with the same name. As an alternative you can use the --rm flag with the docker run command.
A container with the same name is still existing. Containers can exist in following states, during which the container name can't be used for another container: created.
Since there is a container_name:
that you can add to your docker-compose.yml (since PR 1711), one possible workaround would be to:
docker-compose.yml
as a template: copy it and add a random container name in a new container_name: xxx
directive.docker compose up
on that temporary docker-compose.yml
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With