To start a Docker container I ran the command docker compose up -d
. (Actually, the -d
switch is unimportant.)
docker ps
shows the following containers are running.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
678ef93d18dc python-my-python-project "python3 -m my_pytho…" 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp python-my-python-project-1
Where do the image and container names come from? How are these strings generated?
Image Name: python-my-python-project
Container Name: python-my-python-project-1
Contents of Dockerfile
:
# syntax=docker/dockerfile:1
from python:3.12-bookworm
workdir /python-my-python-project
copy ./my_python_project ./my_python_project
copy ./requirements.txt .
run pip3 install --no-cache-dir --upgrade -r requirements.txt
cmd ["python3", "-m", "my_python_project"]
expose 80
Contents of docker-compose.yml
:
services:
python-my-python-project:
build: .
ports:
- "80:80"
I haven't been able to find any documentation about how the names are created. I understand that the name should not be manually specified in either the Dockerfile
or docker-compose.yml
specification because manually pinning the name causes problems when trying to deploy containerized applications as part of a swarm.
What "rule" causes the name python-my-python-project
to be generated?
python-my-python-project
in your case. See github.com/docker/compose/blob/…-p
option on compose commands and defaults to the current directory name. Service name and instance name are pretty self explanatory. This is with compose 2.19.1.