4. Docker Mount

Parmeshwar C
2 min readJan 16, 2021

Here we are going to cover how to preserve data outside our container because when the container exits it destroys all the data inside. Which is the biggest problem? But there are ways to sync data out of the container. Let’s find out.

Volume — inside docker host

  1. It creates volume automatically if it is not present
  2. Create volume using command -
docker run — mount src=”$(pwd)”,target=$HOME/app,type=volume webapp:1.0

Bind — outside docker host but on host machine.

  1. It does not create a directory if not present but will send an error
  2. Add mount using the command
docker run — mount src=”$(pwd)”,target=$HOME/app,type=bind webapp:1.0

The type parameter itself mentions its approach. Both the approach have their own merits and demerits. In one line volume is crated inside the docker host machine so those are platform independent where host mount is dependent on the host machine so command and paths may differ in second approach.

--

--