Doesn't replace container after building a new Dockerfile image
Describe the bug
I have a project with a custom Dockerfile.
If I update the Dockerfile without updating docker-compose.yml and run sudo podman-compose up --build then the new image is built, but it doesn't replace the current container with one using the new image. Instead it prints the warning
Error: creating container storage: the container name "test_podman_compose_python_1" is already in use by 6cbc30b3bcd7130e7dbaf63fdeab8c8652b09385ec39c5035ff6bbd3a03abdf6. You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so.
To Reproduce
A directory with the following three files is sufficient:
docker-compose.yml:
services:
python:
build: .
command: python -m pip list
Dockerfile:
# pull official base image
FROM docker.io/python:alpine3.20
# install python dependencies
RUN pip install --upgrade pip
# RUN pip install numpy # <-- uncomment this
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/local/bin/
RUN sed -i "s/\r$//g" /usr/local/bin/entrypoint.sh \
&& chmod +x /usr/local/bin/entrypoint.sh
# run entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
entrypoint.sh:
#!/bin/sh
exec "$@"
You should then
- Run
sudo podman-compose up --build - Uncomment
# RUN pip install numpy # <-- uncomment this - Run
sudo podman-compose up --build
Expected behavior It should print
[python] | Package Version
[python] | ------- -------
[python] | pip 24.2
followed by
[python] | Package Version
[python] | ------- -------
[python] | numpy 2.1.1
[python] | pip 24.2
NOTE: This is the current behaviour of docker-compose.
Actual behavior It prints
[python] | Package Version
[python] | ------- -------
[python] | pip 24.2
followed by
[python] | Package Version
[python] | ------- -------
[python] | pip 24.2
Environment:
- OS: Linux
- podman version: 5.2.3
- podman compose version: 1.2.0 (release version)
Even here, my code has fixes for dynamic frame resolution, even using stop, rm, build, up, the fixes are not reflected.
There is a hint here about the solution:
You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so.
When using podman-compose, you can pass the replace argument to podman like this:
podman-compose --podman-run-args='--replace' -f compose.yml up