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
Labs

Storing Container Data In Docker Volumes

Storing data within a container image is one option for automating a container with data, but it requires a copy of the data to be in each container you run. For static files, this can be a waste of resources. Each file might not amount to more than a few megabytes, but once the containers are scaled up to handle a production load, that few megabytes can turn into gigabytes of waste. Instead, you can store one copy of the static files in a Docker volume for easy sharing between containers. In this lab, you will learn how Docker volumes interact with containers. You will do this by creating new volumes and attaching them to containers. You'll then clean up space left by anonymous volumes created automatically by the containers. Finally, you'll learn about backup strategies for your volumes.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 45m
Published
Clock icon Nov 20, 2020

Contact sales

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

Table of Contents

  1. Challenge

    Discover Anonymous Docker Volumes

    1. View the currently available Docker images.
    2. List any existing Docker volumes.
    3. Run two postgres:12.1 containers in detached mode.
    4. Inspect the postgres containers to learn about the attached volumes.
    5. Run another detached postgres container using the --rm flag.
    6. List the Docker volumes, then shut down the postgres containers to see what effect that has on the volumes.
  2. Challenge

    Create a Docker Volume

    1. Create a Docker volume for the website code.
    2. Copy the website code into the volume from the host. You will need to use root permissions.
  3. Challenge

    Use the Website Volume with Containers

    1. Run an httpd container and mount the data volume. Expose container port 80 to view the website.
    2. View the webpage in a browser. Use the public IP address of your instance.
    3. Run another httpd container using the --rm flag. What do you expect will happen with the data volume when this container is stopped?
    4. List the current Docker volumes.
    5. Stop the temporary httpd container.
    6. List the Docker volumes again. Did the volume behave like you expected?
  4. Challenge

    Clean Up Unused Volumes

    1. Remove any volumes not currently in use.
    2. View the new list of volumes.
  5. Challenge

    Back Up and Restore the Docker Volume

    1. Inspect the website Docker volume to find its location on disk.
    2. Back up the Docker volume from the host by using tar to create a compressed archive.
    3. Back up the Docker volume from a container by mounting the volume and a backup data location to another container.
    4. Restore a backup.

    Note: Because the Docker data directories are protected, change to the root user for this task using sudo su - and the provided password.

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