Mount current directory as a volume in Docker on Windows 10

Cover Image for Mount current directory as a volume in Docker on Windows 10
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

πŸ˜ŽπŸ”–πŸ’» Welcome to the Docker Dazzle Blog! Today, we're going to tackle a common problem faced by Windows 10 users who want to mount their current directory as a volume in Docker. 🐳πŸ’₯

So you've built a Docker image that's running smoothly, but you're struggling to mount the current path. You'd love to use container executables as commands in your current path, right? We're here to help you make that happen! πŸš€πŸ”§

Before we dive into the solution, let's set the stage. You're using Docker version 1.12.5 on Windows 10 via Hyper-V. You've got a drive, let's say it's E, with a folder named "test." Inside "test," there's another folder called "folder on windows host," just to showcase that the command is working. To make this work, your Dockerfile creates a directory called /data and defines it as both a VOLUME and WORKDIR. So far, so good! πŸ‘Œ

Now, you want to use the current directory instead of an absolute notation. Makes sense, right? But when you try different approaches, like using pwd in the volume, you encounter some frustrating error messages. Let's take a look at the failed attempts: 🚫❌

  1. Trying with ($pwd):

PS E:\test> docker run --rm -it -v ($pwd):/data mirkohaaser/docker-clitools ls -la

Error: ":/data" is not a valid repository/tag.

  1. Trying with /($pwd):

PS E:\test> docker run --rm -it -v /($pwd):/data mirkohaaser/docker-clitools ls -la

Error: E:\\test is not a valid repository/tag.

  1. Trying with \Β΄pwd\Β΄:

PS E:\test> docker run --rm -it -v Β΄$pwdΒ΄:/data mirkohaaser/docker-clitools ls -la

Error: Invalid bind mount spec "Β΄E:\\testΒ΄:/data": invalid mode: /data.

  1. Trying with pwd:

PS E:\test> docker run --rm -it -v `$pwd`:/data mirkohaaser/docker-clitools ls -la

Error: "$pwd" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.

Oh boy! These error messages can be quite confusing, right? But fear not, the correct syntax is just a heartbeat away! πŸ’ͺπŸ’‘

To mount the current directory as a volume in Docker on Windows 10, you need to use $(pwd) instead of ($pwd). So, here's the correct command to make your dreams come true: πŸŽ‰βœ¨

docker run --rm -it -v $(pwd):/data mirkohaaser/docker-clitools ls -la

By using $(pwd), you're instructing Docker to fetch the current directory, and then magic happens! You successfully mount the current directory as a volume in the Docker container. Go ahead, give it a try! πŸ’ͺπŸƒβ€β™€οΈ

We hope this guide has helped you solve the puzzling issue of mounting the current directory as a volume in Docker on Windows 10. If you found this helpful, make sure to share it with your fellow Docker enthusiasts and check out our blog for more Docker tricks and tips. πŸŽ―πŸ“š

Have other Docker problems or tech questions? We're here to help! Drop a comment below and let's start a conversation. Together, we can conquer the Dockerverse! πŸŒŸπŸ’»


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

πŸ”₯ πŸ’» πŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! πŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings πŸ’₯βœ‚οΈ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide πŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? πŸ€” Well, my

Matheus Mello
Matheus Mello