When to use Docker commit command to create a new image based on the conatiners changes

I am using Jupyter notebook in a Docker container that I am running. I have saved the Jupyter notebook. I am still in the container and the notebook is running.

My question is when do i save the conatiner as an image using the commit command?
I am afraid that if I get completely out of the Jupyter notebook that is equivalent to a exiting the container and
by that time all changes to the container are lost and using the commit comand will only create a copy of the original image that I started out with.

That would lose all of the changes that I made forever and hours of work would be lost.

So at what point now do I use the commit command?

Any help appreciated. Thanks in advance.



docker commit – Creates a new image from a container’s changes
docker save _ Save one or more images to a tar archive

If it’s about improving the image itself: instead of applying manual changes, it is strongy suggested to automate the process using a Dockerfile and docker build. It is easy to learn.

Though, If you just want to create an image because you don’t want to lose persistant data… you probably didn’t use docker volumes to mount one or more host path / remote share to store the data outside the container.

No one realy uses the commit command.

You really want to save your notebooks on your hard drive and not in the container. This is what I do.

In my ~/.bash_profile I have the following alias (btw, I’m on macOS):

alias jupyter='docker run --rm -p 8888:8888 -v $(PWD):/opt/notebooks continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/jupyter notebook --ip= --port=8888 --notebook-dir=/opt/notebooks --allow-root --no-browser"'

Whenever I need to use Jupyter I just cd into the folder that I want to save my notebook and issue the command:


That’s it! Jupyter will run in a Docker container and it displays the URL that I need to use to access it. The output looks something like this:

$ jupyter
[I 18:11:40.415 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 18:11:40.617 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.7/site-packages/jupyterlab
[I 18:11:40.617 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 18:11:40.619 NotebookApp] Serving notebooks from local directory: /opt/notebooks
[I 18:11:40.619 NotebookApp] The Jupyter Notebook is running at:
[I 18:11:40.619 NotebookApp] http://7e042f5cd84d:8888/?token=e907fe10763ec8d8c8283fbf930381123df2791b1f6588b2
[I 18:11:40.619 NotebookApp]  or
[I 18:11:40.619 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:11:40.622 NotebookApp] 
    To access the notebook, open this file in a browser:
    Or copy and paste one of these URLs:

Then I cut and paste the last URL into my browser and I’m all set. All of my notebooks are saved on my hard drive. I can safely update the Docker images with the latest version of Jupyter and know that all of my notebooks are safe on my local hard drive. I find this to be the best workflow.