Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Tech News
  • Contact
  • Toggle search form

Create and Mount Volume to Docker Container

Posted on 07/01/202315/08/2026 Imoh Etuk By Imoh Etuk No Comments on Create and Mount Volume to Docker Container
  1. Home
  2. Containers
  3. Create and Mount Volume to Docker Container
Docker-Volumes

In this guide, you will learn how to create and mount the host volume in a Docker container. Containers play a crucial role in application deployment. Docker is one of the most widely used open-source container runtimes. Please see How to manually update Docker desktop, how to install and uninstall Docker Desktop on Windows 10 and Windows Server, and How to manually update Docker desktop.

Docker volumes are popular and practical solutions for ensuring data persistence when working with containers. They are a better option than bind mounts, which depend on the directory structure and OS of the host computer because Docker entirely manages them.

Volumes defeat building additional writable layers that increase the size of the Docker image. Using Docker Volume is suitable when working on a micro-service architecture using Docker containers in order to build and test various application components.

Willing to learn more about Docker? See related posts as follows: How to Set up a Private Docker Registry, how to Run Docker commands returns Docker is not recognized as an internal or external command, Running Docker commands returns Docker is not recognized as an internal or external command

What are Volumes?

Before proceeding to the demo section, understanding what Docker Volumes are is necessary.

In a short and simple sentence, Docker volumes are file systems mounted on Docker containers for the purpose of preserving data produced by the container while it is running.

A volume does not increase the size of the containers that use it, and the contents of a volume live outside the lifespan of a particular container, making them a frequently preferable option to persisting data in a container’s writable layer.

Working with Docker Volumes

During container launch, several possible approaches to mounting a Docker volume exist. The -v and --mount flags that are added to the docker run the command is up to the user to decide.

Below are a few things to know about Docker Volumes:

  1. When the container disappears, the data is lost, and removing the data from the container can be challenging.
  2. Bind mounts are more difficult to transfer or backup than volumes.
  3. Volumes can be managed using the Docker API or the Docker CLI
  4. Both Linux and Windows containers support volumes.
  5. Shared volumes between numerous containers can be done more securely.
  6. Docker Volume is one of the concepts required in order to maintain Data persistence in the Docker container.

Getting Started with Docker Volume

To get started with mounting a Docker Volume, one of the criteria is to have Docker installed on your system. To learn how to install and set up Docker on your Ubuntu Machine, refer to this post on How to install Docker Engine on Ubuntu. After setting up Docker on your machine, run the docker --version command verify that installation.

Checking-Docker-Version
Checking Docker Version

Now that you have set up Docker on your machine, run the docker volume ls command to check the existing volumes.

Existing-Volumes
Checking the Existing Docker Volumes

Creating a Volume

The docker volume create command is a perfect command to run to create a Docker Volume. To do so, run:

sudo docker volume create <volume name>

Verify the newly created volume as shown in the screenshot below. Remember to specify a unique name for your Volume.

Creating-and-verifying-the-volume
Creating and verifying the new docker volume

Also, see How to stop Docker from automatically starting on Mac, and how to fix “Failed to remove network for build: Error during connect in the default daemon configuration on Windows, the Docker client must be run with elevated privileges“.

Inspecting Docker Volume

Now that we have created a Volume, it’s time to inspect the volume. To do so, run the command below:

docker inspect <volume-name>
Inspecting-Docker-Volume
Inspecting a Docker Volume

Mounting Docker Volumes

Having created and inspected the Docker Volume, we will mount the volume to a Docker Container. With the help of the -v flag, we’ll mount the my-volume Volume to the Docker Container we’ll create using an Ubuntu base image.

sudo docker run -it -v my-volume:/shared-volume --name ubuntu-container-001 ubuntu

Running the above command will create the ubuntu base image container and mount the volume. From the screenshot below, we create a file named Test-file.txt and exited the container with the exit command.

Create-a-file
Mounting Docker Volume and Creating a File

Now, let’s create another  Docker Container called ubuntu-container-002 and mount the same Docker Volume called my-volume  inside the Container using the below command:

sudo docker run -it -v my-volume:/shared-volume --name ubuntu-container-002 ubuntu
Mounted-Second-Container
Creating Another Volume and Verifying the Content

If you change the directory to the share-volume directory and use the ls command to list the content you will see the same test-file.txt file that was created in the same <my-volume> Volume but mounted in ubuntu-container-001.

This is because the my-volume Volume is shared between two containers that are ubuntu-container-001 and ubuntu-container-002.

To summarize, we discussed how to create, inspect, and mount a Volume to multiple Docker Containers in this post. This is extremely useful when multiple Docker Containers require shared access to files and directories.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Containers, Linux Tags:Ubuntu

Post navigation

Previous Post: Install and use Burp Suite for Web Application Security Testing
Next Post: Performance and Diagnostics in Microsoft Cloud with Azure Monitor

Related Posts

  • ysvxdf
    Install and configure BigBlueButton on Ubuntu Linux Linux
  • How to configure Azure container register with secured connection with container apps
    Configure Azure Container Registry for a secure connection with Azure Container Apps AWS/Azure/OpenShift
  • 517443 637084112713220326 16x9 1
    How can I tell if a password is set for a user account on Linux Linux
  • centos feature
    How to change the system time zone under RedHat and CentOS Linux
  • Screenshot 2020 05 14 at 18.00.59
    Linux Error 13: Permission denied – Are you root Linux
  • MV command in Linux
    Rename or Move Files or Directories in Linux with Bash Terminal Linux

More Related Articles

ysvxdf Install and configure BigBlueButton on Ubuntu Linux Linux
How to configure Azure container register with secured connection with container apps Configure Azure Container Registry for a secure connection with Azure Container Apps AWS/Azure/OpenShift
517443 637084112713220326 16x9 1 How can I tell if a password is set for a user account on Linux Linux
centos feature How to change the system time zone under RedHat and CentOS Linux
Screenshot 2020 05 14 at 18.00.59 Linux Error 13: Permission denied – Are you root Linux
MV command in Linux Rename or Move Files or Directories in Linux with Bash Terminal Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

Veeam Vanguard

  • Fix Operating System Loader failed signature verification e1778595875592
    Fix Operating System Loader failed signature verification” on Dell Safe BIOS Systems via PXE [Part 3] Windows
  • s3
    How to Copy from a server to s3 and vice versa AWS/Azure/OpenShift
  • 1 kajkbmlyehn0inifwrh 8w 1
    How to configure Kerberos for Ansible Authentication Configuration Management Tool
  • image 64
    How to install Fax Server on a Windows Server Windows
  • screenshot 2020 02 08 at 17.31.28
    How to perform Password Change with OWA Network | Monitoring
  • cannot connect to the virtual machine try to connect again HyperV
    Could not connect to virtual machine try to connect again Hyper-V Virtualization
  • fghj
    Windows Profile: How to determine your windows username Windows
  • ext
    How to install a standalone DriveLock Encryption software on Windows Security | Vulnerability Scans and Assessment

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,765 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.