An Intro To Docker Volume

Creating a locally developed containerized service is quite slow. To test every code change, the developer would have to make the code change then destroy the existing container, rebuild the container and restart it. Volumes makes that process efficient.

When a container is destroyed, any state is lost with it. Docker offers volumes which could be mounted to a container allowing data to be persisted outside of a container’s standard lifecycle. This is used for running databases and containers that allows avoiding rebuilding containers with every code change.

To run volumes, add “-v” to the regular docker run command. Map the host machine’s source directory to the container’s source directory. Mounting the host machine’s source directory to the container’s source directory, allows changes on either side whether from the host machine or the container.

By simply mounting the host machine’s source directory to the container’s app source directory, we’re allowing the programme to detect the code changes from the host machine and instantly restart the server.

Junior Front-end Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store