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: filter docker ps on Compose labels to see one project's containers

Docker
~/tips/tip-docker-ps-filter-compose-label

docker ps --filter label=com.docker.compose.project=media \

Use the labels Compose adds to find containers by project or service anywhere.

Compose puts labels on every container it creates, such as the project and the service name. Plain docker commands can filter on them, so you can find a project’s containers from any folder.

docker ps --filter label=com.docker.compose.project=media \
  --format 'table {{.Names}}\t{{.Label "com.docker.compose.service"}}\t{{.Status}}'

That lists the containers of the media project with their service name and status. Other labels that are there: com.docker.compose.service, com.docker.compose.project.working_dir (the folder the project lives in) and com.docker.compose.project.config_files.

The working directory label is my favourite. When you find an old container and wonder which Compose file started it, this tells you:

docker inspect --format '{{index .Config.Labels "com.docker.compose.project.working_dir"}}' mycontainer

You can add your own labels too, with labels: in Compose or -l on docker run, and filter on them the same way.

These labels are set by Compose for its own bookkeeping. Do not edit or copy them onto containers made by other tools, because Compose uses them to decide which containers belong to a project and may stop or remove the wrong one.

Further reading: docker container ls: filtering, Docker object labels

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