containers / containers/podman-compose

Doesn't replace container after building a new Dockerfile image

Open
#1,053 2 comments 6 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
6.2k
Forks
622
PR merge metrics
No merged PRs in 30d

Description

**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
1. Run `sudo podman-compose up --build`
2. Uncomment `# RUN pip install numpy # <-- uncomment this`
3. 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)

Contributor guide

Open the contributing guide

Research direction

Start by tracing the podman-compose up --build flow for the provided docker-compose.yml and Dockerfile, focusing on the container-creation warning about the existing name. Confirm the behavior with the three-file reproduction, then verify that rebuilding replaces the current container and produces the expected pip list output including numpy.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
build-system, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.