Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

Using Volumes in Docker Containers

Containers are designed to be ephemeral, so when you need persistent data, it is usually not a good idea to store it directly in the container's file system. This is where Docker volumes come into play. Docker volumes allow you to store persistent data outside the container itself, providing greater flexibility in what you can do with your data. In this lab, you will have the opportunity to solve a complex problem using Docker volumes. You will have a chance to work with both shared volumes and bind mounts in order to implement two containers which work together, one container transforming data created by the other. This will give you some practice in working with volumes, as well as some insight into the many ways in which Docker volumes can be used.

Google Cloud Platform icon

Path Info

Clock icon Intermediate
Clock icon 45m
Clock icon Jun 06, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create the shared volume and counter container to generate some sample data.

    1. Create a shared volume.
    docker volume create test-data
    1. Create the counter container with the provided command, and mount the shared volume to the container.
    docker run --name counter -d 
      --mount type=volume,source=test-data,destination=/var/log/test 
      sh -c 'i=0; while true; do echo "$i: $(date)" >> /var/log/test/1.log; i=$((i+1)); sleep 1; done'

    You can confirm that the counter container is generating data by examining the file inside the container:

    docker exec counter cat /var/log/test/1.log
  2. Challenge

    Create the fluentd container to transform and output the data from the counter container.

    1. Create the fluentd container and mount the shared volume, the config file, and the output directory to it.
    docker run --name fluentd -d 
      --mount type=volume,source=test-data,destination=/var/log/input 
      --mount type=bind,source=/etc/fluentd/fluent.conf,destination=/fluentd/etc/fluent.conf 
      --mount type=bind,source=/etc/fluentd/output,destination=/var/log/output 
      --env FLUENTD_ARGS="-c /fluentd/etc/fluent.conf"
    1. Verify that the fluentd container is generating output on the Docker host.
    ls /etc/fluentd/output

    You should see some files containing the transformed log data.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans