brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: name: in a Compose file fixes the project name

Docker
~/tips/tip-compose-top-level-name

name: storefront

Gives a compose stack a fixed project name instead of the folder name.

Compose names the containers, networks and volumes of a stack after a project name, and by default that name is the folder the compose file sits in. Two checkouts in folders with the same name look like one project.

Set the name in the file itself:

name: storefront
services:
  web:
    image: nginx:stable

Compose picks the project name in this order, highest first:

  • the -p flag
  • the COMPOSE_PROJECT_NAME environment variable
  • the top-level name:
  • the folder that holds the compose file
  • the current folder, when no compose file is given

So name: gives the stack a stable default, and -p still wins when you want a second copy next to it:

docker compose -p storefront-test up -d

The name is the prefix of what Compose creates, for example storefront-web-1 for the container and storefront_default for the network. Two projects with the same name get in each other’s way for that reason.

Caveat: renaming the project later does not rename what already exists. Compose sees new containers and volumes under the new name, and the old ones stay behind. Pick the name before the first up, and use docker compose ls to see which projects Compose knows about.

Further reading: Specify a project name

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link