Docker Toolbox
Windows
volume option
Docker tutorial
Docker volumes

How to use --volume option with Docker Toolbox on Windows?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Docker Toolbox, a collection of tools for managing Docker containers and images on Windows and Mac, provides a way to use containers on systems where Docker Desktop is not natively supported, such as older versions of Windows. One of the essential features that allow seamless integration between a containerized environment and the host system is the use of volumes, particularly through the --volume option.

Volumes represent a method for persistently storing data generated or used by Docker containers. They are the preferred mechanism for data management within containers, offering advantages in terms of performance and ease of use compared to traditional file systems.

Using the --volume Option in Docker Toolbox

In Docker Toolbox, the --volume or -v option allows you to create and manage volumes on Windows. This option binds one or several directories on the host system to directories in a container, facilitating persistent storage and data sharing.

Technical Breakdown of --volume

  • Syntax: The basic syntax for using the --volume option is:
  • Host Directory: The path on the host machine. Within Docker Toolbox, this path must be within the VirtualBox shared folder directory, typically /c/Users.
  • Container Directory: The path inside the container where the volume is mounted.
    • -d runs the container in detached mode.
    • -p 80:80 maps port 80 on the host to port 80 in the container.
    • -v /c/Users/YourName/my-web-content:/usr/share/nginx/html binds the host directory to the container directory used by NGINX to serve files.
  • Path Specification: The Docker Toolbox employs a VirtualBox VM running Linux. Hence, paths use /c to access the C: drive of Windows.
  • Data Persistency: Changes in the container directory will reflect in the host directory unless explicitly overwritten by container operations.
  • Permissions: Manage file permissions carefully, as the host and container run on separate operating systems. Ensure both systems can read/write as necessary.
    • Using volumes to mount source code directories encourages rapid development and testing by reflecting changes instantly in the container.
    • Volumes can act as a backup for essential data by moving it out of volatile container storage.
    • Separate configurations from application code by mounting configuration files and directories as volumes.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.