windows programming

[0] Windows version of Linux’s $(pwd) no more headaches


Docker in Windows

Tonight, I played around with Docker in Windows, and I wanted to use Node to install my packages to my local environment. Then I found a command on Chris Fidao’s Laravel Vessel website, which looked like…

docker run --rm -it -v $(pwd):/opt -w /opt shippingdocker/php-composer:latest composer create-project laravel/laravel my-app

I modified it for use with npm to…

docker run --rm -it -v $(pwd):/opt -w /opt node npm i vuepress

I ran this command and got the following…

docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only 
"[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path. See 'docker run

Is there a pwd command in Windows?

A quick search and I found I could replace $(pwd) with cd equivalent in Windows which looked exactly like this…

docker run --rm -it -v %cd%:/opt -w /opt node npm i vuepress
Screenshot of running "docker run" in Windows command line with %cd%

If you enjoyed this post, please consider supporting me on Ko-Fi.

UPDATE: If you’re reading this, you probably won’t even need to know this anymore.

WSL2, which can be installed really easily, and you can use Docker with it. This means you can run Ubuntu and have Unix based commands. If you’re running a modern Windows setup, you can install WSL2 on your Home or Pro version install.

I have been using the WSL2 setup for a few years, and I have found minimal issues. You can even install Go, Python, PHP, Apache, NGINX, Node etc., using the native apt installer. If you’re not one to use Ubuntu, you can also use Kali, Debian and SUSE. However, it would be great if they could add CentOS or other Red Hat distributions.

PHPStorm works with WSL2 as long as you know where your WSL2 project is located. Say you’re using Ubuntu. You can open the terminal and type…

explorer.exe .

It will open a new explorer window, and you can copy/paste the file location into PHPStorm to open up the project and edit your files. Visual Studio Code also works well with WSL2, which probably goes without saying because it’s a Microsoft product. You don’t need Git, composer or anything like that installed because it can all be installed inside WSL2 and be 100% native to Unix. WSL2 has become very fast to use and has massive support from various companies. The subsystem is only getting better, and while it did have a rocky start, it seems like most issues have now been fixed.

If you haven’t tried WSL2 yet, I highly recommend it. I prefer it to dual-booting a Linux based OS because I can now have everything under one OS. The only downside is, you don’t get a GUI Linux based OS. However, they are looking to add that very soon, and it is currently in the developer builds for testing. Once it is out, I will create a new post to describe my experiences with it.

What can I use GUI application support for?

WSL lets you run a Linux environment, and up until this point, it has focused on enabling command-line tools, utilities and applications. GUI app support now lets you use your favourite Linux GUI applications as well. WSL is used in a wide variety of applications, workloads, and use cases, so ultimately, it’s up to you on what you’d like to use GUI app support for. Below, we’ve highlighted some key scenarios to help you fall in love with running applications in a Linux environment.

Hopefully, if the changes look promising, we can do even more in a single OS with even less reason for dual-booting. It’s certainly something I will be keeping my eye on from now on.

Powershell Pwd also works as part of the Windows shell commands.

Ls in Windows should be changed to dir.

If you enjoyed this post, please consider supporting me on Ko-Fi.


4 responses to “[0] Windows version of Linux’s $(pwd) no more headaches”

  1. […] Windows version of Linux’s $(pwd) […]

  2. joel avatar

    hi friend

    please whats windows wersion of these

    root@aa89314fe141:/opt/esp/lib-builder# cp -a pro/* ~/Arduino/hardware/espressif/esp32

    Error message
    cp: target ‘/root/Arduino/hardware/espressif/esp32’ is not a directory

    1. Michael Brooks avatar

      Hi Joel. It looks like an Arduino issue and not a Windows issue. Unfortunately, I haven’t got any experience with Arduino. I hope you can find a solution soon.

  3. Vl.k avatar

    I have a problem. Can you help me?

    invalid reference format: repositorydocker run –name haproxy –net mynetwork -v %cd%:/usr/local/etc/haproxy:ro -p 80:80 -p 8404:8404 haproxytech/haproxy-alpine:2.4
    docker: invalid reference format: repository name must be lowercase.
    See ‘docker run –help’. name must be lowercase.

Leave a Reply