9

When you are running a docker-compose up -d command, by default the build image is going to take the name of the current folder.

So for example for this docker-compose.yml file my image will be named: dockersymfony_php because my current folder is named docker-symfony and I indicated php for my image in my yaml file

php:
    build: ./docker/php
    container_name: symfony

Is there a way to override that ? Like container_name to renaming the container...

I know that the command docker build -t . can do it but I need to use my docker-compose.yml file.

2 Answers 2

8

Currently all you can do is customize the project name (the first part of the name before the underscore) using -p flag:

docker-compose -p COMPOSE_PROJECT_NAME

In the next release you'll be able to use image to set the name: https://github.com/docker/compose/issues/2092

Sign up to request clarification or add additional context in comments.

3 Comments

What version of docker-compose supports this? Doesn't work with 1.5.2 build 7240ff3.
supports which? Setting the project name has always been supported. The linked issue will be in 1.6.0
You're right. Maybe I ran docker instead of docker-compose.
2

As of Jan 2018, with version 3 of Docker compose you can use container_name to specify the name. An example can be found here https://www.handsonarchitect.com/2018/01/docker-compose-tip-how-to-avoid-sql.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.