How do you update a running docker image on digital ocean droplet? [duplicate]

I have a docker image running on port 3000 on my droplet on digital ocean.

I did some updates and created a new image and pushed it to my github packages.

I thought when I push the new image that the old one would just get overriden but Im getting an error saying

"Bind for 0.0.0.0:3000 failed: port is already allocated".

I run the following command when I get the above:

docker run -p 3000:3000 docker.pkg.github.com/UserName/Project/newImageName:1

This made me think that I could remove the old image and add the new one but that does not seem ideal but I have not found a command that can override/update to a new one.

Is this possible, and how?


Solution 1:

Run the image using --rm parameter (which removes the container upon exit).

docker run --rm -p 3000:3000 docker.pkg.github.com/UserName/Project/newImageName:1

After exiting (stopping the container) you can docker pull to get the latest version of the image and then re-run