Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add container_name for docker commands locally #2545

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

hanhanhan
Copy link
Contributor

Description

Add docker-compose configuration container_name. This makes it possible to run docker commands without looking up the container hash.

Examples

docker exec -it django /bin/bash
docker top django

instead of

docker exec -it 5E34B0 /bin/bash
docker top 5E34B0

Considerations

  • Users can't have two containers with the same name. So, if users build multiple cookiecutter-django docker projects locally they will run into this problem. Docker will warn the user to rename the container though.
  • Ignored in swarm mode.
  • You might not like the names I picked. Do you prefer something closer to the image name for all services?

Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thanks for contributing to cookiecutter-django!

This change would be good to make the docker command line friendlier, and would be nice. However I'm a bit conerned by the warning in the documentation:

Because Docker container names must be unique, you cannot scale a service beyond 1 container if you have specified a custom name. Attempting to do so results in an error.

So it looks like we wouldn't be able to run 2 (or more) Django containers? I assume it might be a common use case for folks on production...

Usually, I tend to stick to docker-compose (mainly because it uses service names), along with a shell alias (e.g. alias dcl='docker-compose -f local.yml'). The commands you gave as example are available with human-friendly names:

  • docker-compose -f local.yml exec django /bin/bash
  • docker-compose -f local.yml top django

Or with the alias:

  • dcl exec django /bin/bash
  • dcl top django

Have you faced any issues with multiple container when this is specified? Would the solution via Compose be suitable?

@browniebroke
Copy link
Member

Ok, I'm fine with having it only for local development, that sounds like a reasonable compromise.

Thanks for the patch!

@browniebroke browniebroke changed the title Add container_name for docker commands Add container_name for docker commands locally Apr 21, 2020
container_names make it possible to run docker commands
without looking up container hash
use in dev.yml
@browniebroke browniebroke merged commit d86bd32 into cookiecutter:master Apr 28, 2020
@browniebroke
Copy link
Member

Thanks for the improvements! 🎉

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants