Docker restart container with new image

To restart a Docker container with a new image, you can use the following command:

docker restart --image <new_image_name> <container_name>

Replace <new_image_name> with the name of the new image you want to use, and <container_name> with the name of the container you want to restart.

For example:

docker restart --image my-new-image my-container

This will stop the container, remove it, and then create a new container with the same name using the new image.

Alternatively, you can use the docker update command to update the image of an existing container:

docker update --image <new_image_name> <container_name>

This will update the image of the container without stopping it. If the container is running, it will be restarted with the new image.

Note that if you want to preserve the changes made to the container's filesystem, you should use the docker commit command to create a new image based on the current state of the container, and then use that new image to restart the container.

For example:

docker commit my-container my-new-image
docker restart --image my-new-image my-container

This will create a new image based on the current state of the container, and then restart the container with that new image.