Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix basename of containers when using docker-compose?

It seems that docker-compose adds current folder name as a base-name for each created container. So for following directory structure:

/myproj/docker-compose.yml

and docker-compose.yml content:

web: ...
worker: ...

docker-compose will create following containers:

myproj_web_1
myproj_worker_1

I don't mind the suffix (_X) however I would like to "fix" myproj to some constant like "always_same" so I could move docker-compose.yml file around and still have containers with same names.

How I can do it?

like image 742
user606521 Avatar asked Aug 19 '15 16:08

user606521


People also ask

Do you need Dockerfiles with docker-compose?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

Does docker-compose remove containers?

Stops containers and removes containers, networks, volumes, and images created by up .

How do I debug a docker-compose file?

If you want to debug in Docker Compose, run the command Docker Compose Up using one of the two Docker Compose files as described in the previous section, and then attach using the appropriate Attach launch configuration. Launching directly using the normal launch configuration does not use Docker Compose.

How do you stop the container in detached mode?

To stop this container, press Ctrl+C in the terminal where it was started. Alternatively, you may start a container in detached mode using the -d option. To see all running containers, use the docker ps command.


1 Answers

There are two ways to do this.

Set the environment variable with

export COMPOSE_PROJECT_NAME=foo

or by starting your stack with the -p switch

docker-compose -p foo build
docker-compose -p foo up
like image 80
Jay Avatar answered Nov 15 '22 22:11

Jay