Please note that I have changed a little bit my Dockerfile, so that my working directory will the docker volume and package.json to use nodemon so that the node server will restart after any changes, my files now look like this: // Dockerfile So, let’s try this out, I’m going to use the folder of my node web app created above to link it to docker volume. One of the most developer oriented nice feature of docker volume is, the possibility of using a host folder as volume by doing so, a developer for instance can bind his/her workspace to a docker volume and run a container using that volume, so any change made in the workspace is automatically reflected on the related volume, which a cool feature from developer standing point. "Mountpoint": "/var/lib/docker/volumes/cadf05a38efc5c2445f5f7b848c16c3fa2c15e1a036a9b4cad40acc1a9e74371/_data",Īnother way to create volumes within the container creation is by adding VOLUME to Dockerfile like: VOLUME Using host folder as volume We can also inspect the created docker volume using the volume Id:.In the Mounts array we have “Source” field which is the folder in the host machine linked to the create volume inside the container, which the “Destination” field. ➜ DockerVolumes docker inspect nodewebapp Inspecting our container to check our created volume, to do so, run.We can test our node web just using curl.Let’s run a container with a volume using our last built image, node we will bind public port 3001 to the private (inside our container) port 3000 of our node server:.Removing intermediate container bc82f32eef88 Removing intermediate container bdb0b1c0881b Sending build context to Docker daemon 5.12 kB ➜ DockerVolumes docker build -t linoxide/nodewebapp. Build our docker image and tag it using –t flag.Let's create a docker image (node js image) and setup a sample node web app to work with throughout this article:ĭockerfile node_modules package.json server.jsĬonsole.log('Server listening on port 3000!')
When we create and start a docker container using the command docker run we can specify a volume to be attached to the created container by adding the argument -v and specifying a folder path of the volume like illustrated bellow. In fact, there are several ways to create docker volumes mainly, either within the container creation lifecycle, or separately.