Assuming you have updated your code and have the Dockerfile in place:
Build a new image from the location your Dockerfile is in place, or give location of Dockerfile.
docker build -t image-name .
docker build -t image-name -f /path/to/Dockerfile .
This will create a new image with your updated code. Be sure to use the same <image-name> as the existing container that you want to replace.
ย Stop the existing container, and remove it.ย
docker stop container-name
Run a new container using image name or if using a docker-compose file:
docker rm container-name
docker run --name container-name -d image-name
docker-compose -f filename.yml -d
This will start a new container using the new image with your updated code. Be sure to use the same <container-name> as the existing container that you just removed, and the same <image-name> as the image you built in step.
After these steps, your new container will be up and running with your updated code. If your container is running a service that is exposed on a port, be sure to map the container’s port to a port on your host machine using the -p option when you run the new container.
docker build -t image-name