I am trying to update the image of a running docker container using the docker library for python.
To update the image, my script executes the following steps:
- look for containers with the given image name
- pull the image from the registry
- create new containers with the configuration from the currently running containers
- stop the old containers
- start the new containers
- remove the old containers
My problem is in step number 3. After creating new containers with the configuration from the old containers, the new containers are not having the exact same config. For Example, I testes my script with the traefik container. The resulting container has only port bindings for port 80 but the original has for ports 80 and 443.
This is the code to 'clone' the containers:
for c in containers:
new_c = docker.APIClient().create_container(c.attrs['Config']['Image'],
environment=c.attrs['Config']['Env'],
host_config=c.attrs['HostConfig'],
labels=c.attrs['Config']['Labels']
)
Is there any way to 'clone' the container configuration or to update the container's image without using the configuration provided with docker run or inside docker-compose?
Hope someone can help me best regards