[Docker] Differences between -v and --mount

2 minute read

Last week, I wanted to upgrade the version of my livebook in Docker. And I had a very strange problem. I did the following:

  • ssh my server

  • docker container stop & rm

  • docker images pull livebook/livebook:latest

  • docker run

No errors occurred during this period and everything looks good. But when I open the page of livebook, the update prompt is still visiting the screen. Then I go to the settings page. The version is still 0.6.1(the latest version is 0.6.3).

The first thing I suspected was the browser, So I check the sessionStorage, localStorage and the Cookie, delete all the infomation of them. And I return the page, the update prompt has no change.

This meant I had to go check the server, I checked the docker image first. The version of images for livebook has no problem after I check the hash. Then I check the port, the container, and any other. All of them have no problem.

After control variables, the last point I have not checked is the --mount. In my docker shell, I use –mount to mounted the directory to save the note of livebook. And i mkdir a customized dir in /var/lib/docker/volumes/my-dir/. When i use -v type=mount instead of --mount, I found the version turned into 0.6.3!

So what's the Differences

Ref from the official explanation:

  • Because the -v and –volume flags have been a part of Docker for a long time, their behavior cannot be changed. This means that there is one behavior that is different between -v and –mount.

  • If you use -v or –volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory.

  • If you use –mount to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not automatically create it for you, but generates an error.

But that doesn't explain why you can't upgrade the version.

In fact, this is because livebook will generate the current version of Release in the directory where it is mounted, and later, even if you change the image, the old release will still be read as the image of the current container.