2

I am new to the dockers so don't really know how to update docker image. I have a python code and I have created its docker image using the below command:

sudo docker build -t mycustomdocker .

After this is done, I can see my docker image using sudo docker images. To run it, I can use:

sudo docker run --restart=always mycustomdocker

This will start its container and with restart always, it will always be running.

Now I want to know for example, I have updated my python code and added some new feature into it. So after updating the python code, its image mycustomdocker automatically gets updated or we need to run any update command for it.? Or do we need to again stop the container, then delete the existing image and again build the image?

Thanks

1 Answer 1

1

It depends on how you are getting files over to the container. If you're using ADD or COPY then yes, you need to stop the running container, rebuild the image and then start it again.

However, what we tend to do, to keep things running quickly is something like:

# ...
ADD ./src/ /something/src/
# ...

And then when running

sudo docker run --volume ${PWD}/src/:/something/src/ --restart=always yourcontainer

Which will override everything in the container /something/src/ file with whatever is in your local ./src/ directory without needing to rebuild. If you do want to publish the container, or run it from anywhere but the directory you're workin in, you will need to build it again.

Read through this article on good storage practices for more info. Also would highly suggest looking into docker-compose to make this even easier, but that's a bit beyond the scope of this question.

Sign up to request clarification or add additional context in comments.

2 Comments

I have created docker using the Dockerfile. ADD ./src/ /something/src/ do you keep this inside the Dockerfile.
If your planning on distributing the images then yes, you need to directly add them with ADD. Volumes just temporarily replaces the directory inside the container.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.