Add docker to path windows

Are you encountering the error message “docker is not recognized as an internal or external command” while trying to run Docker commands?

Don’t worry, this issue is quite common. In this article, you are going to see how to fix it.

Docker is not recognized as an internal or external command 1

As a beginner in Docker, you might come across the error message “docker is not recognized as an internal or external command” when trying to run Docker commands in your command prompt or terminal. This error usually occurs due to misconfigurations in your system PATH variable.

But fret not, we’ve got you covered! This step-by-step guide will help you troubleshoot and fix this error, allowing you to smoothly run your Docker commands.

  • Introduction
  • Understanding the Error
  • Troubleshooting Steps
    • Checking Docker Installation
    • Verifying System PATH Variable
    • Adding Docker to the PATH Variable
    • Restarting Your System
  • Conclusion

Introduction Introduction

Docker is a popular platform used to build, ship, and run applications using containerization. However, it can be frustrating when you encounter the “docker is not recognized as an internal or external command” error. This guide will walk you through the necessary troubleshooting steps to resolve this issue.

Top ↑

Understanding the Error Understanding the Error

When you see the “docker is not recognized as an internal or external command” error, it means that your system cannot locate the Docker executable.

This typically happens when Docker is not added to the system’s PATH variable or when there are misconfiguration.

Docker is not recognized as an internal or external command 2

Top ↑

Troubleshooting Steps Troubleshooting Steps

Checking Docker Installation Checking Docker Installation

Before proceeding with any troubleshooting steps, confirm that Docker is successfully installed on your system. Open your command prompt or terminal and enter the following command:

docker --version

If Docker is installed properly, it will display the version information. If not, make sure to install Docker following the official documentation for your operating system.

Top ↑

Verifying System PATH Variable Verifying System PATH Variable

The system PATH variable allows your operating system to locate and execute executables. To verify if Docker is missing from the PATH variable, follow these steps:

  • Windows: Open the Control Panel and navigate to System and Security > System > Advanced system settings > Environment Variables. Under the System Variables section, check if there is a variable named Path.

If the variable exists, select it and click on the “Edit” button. In the “Edit Environment Variable” window, check if the path to the Docker executable (usually located in “C:\Program Files\Docker…”) is listed. If not, you will need to add it manually.

  • macOS/Linux: Open a terminal window and run the command echo $PATH. Check if the path to the Docker executable is included in the output. If not, you will need to add it manually.

Docker is not recognized as an internal or external command 3

Top ↑

Adding Docker to the PATH Variable Adding Docker to the PATH Variable

To add Docker to the system PATH variable, follow these instructions:

  • Windows: In the “Edit Environment Variable” window mentioned earlier, click on the “New” button and enter the path to the Docker executable (e.g., “C:\Program Files\Docker…”). Click “OK” to save the changes.
  • macOS/Linux: Open your terminal and run the following command, replacing [path-to-docker-executable] with the actual path to the Docker executable:
echo 'export PATH="$PATH:[path-to-docker-executable]"' >> ~/.bashrc
source ~/.bashrc

Top ↑

Restarting Your System Restarting Your System

After adding Docker to the PATH variable, it is recommended to restart your system to ensure the changes take effect.

Top ↑

Conclusion Conclusion

By following these troubleshooting steps, you should now be able to run Docker commands without encountering the “docker is not recognized as an internal or external command” error. Remember to verify your Docker installation, check the system PATH variable, add Docker to the PATH if necessary, and restart your system. Enjoy using Docker to containerize your applications!

If you continue to experience issues, consult the Docker documentation or seek help from the Docker community. Happy containerizing!

Docker is not recognized as an internal or external command 4

Note: Information about Docker installation and configuring the PATH variable may vary depending on your operating system. Please refer to the official Docker documentation for detailed instructions specific to your environment.

Last Updated :
25 Jul, 2024

To determine and operate multi-container Docker applications, you’ll need Docker Compose. The «Docker Compose command not found» error is a frequent problem that many engineers encounter, nevertheless. This problem usually arises from an incorrect setup or non-existence of the Docker Compose binary in the PATH of the system. We’ll look at how to recognize and resolve this error in this post.

Problem Statement

The «Docker Compose command not found» error appears when trying to run a Docker Compose command in the terminal. This prevents users from managing their Docker containers efficiently.

Error Screenshot:

ty11

Approach to Solving the Problem

To solve this error we will follow these steps:

  • The Verify Docker Compose installation.
  • Install or reinstall Docker Compose.
  • Ensure Docker Compose is in the system’s PATH.

Different Solutions to Solve the Error

1. Verify Docker Compose Installation

First, check if Docker Compose is already installed on the system.

$ docker-compose —version

If Docker Compose is installed this command will return the version number. If not we will see the «command not found» error.

2. Install or Reinstall Docker Compose

Installing Docker Compose on Linux

To install Docker Compose on a Linux system follow these steps:

Download Docker Compose:

sudo curl -L «https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)» -o /usr/local/bin/docker-compose

Apply executable permissions to the binary:

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose —version

Installing Docker Compose on macOS

If we are using the Docker Desktop for the Mac Docker Compose is included by the default. Ensure Docker Desktop is installed and running. If not download and install it from Docker website.

docker-compose —version

Installing Docker Compose on Windows

Similar to macOS Docker Desktop for the Windows includes Docker Compose. Ensure Docker Desktop is installed and running. If not download and install it from the Docker website.

Open Command Prompt or PowerShell and check the version:

docker-compose —version

3. Ensure Docker Compose is in the System’s PATH

If Docker Compose is installed but still not recognized it might not be in the system’s PATH. To fix this add Docker Compose to the PATH.

Adding Docker Compose to PATH on Linux

Open the terminal and edit the .bashrc or .zshrc file:

nano ~/.bashrc

Add the following line to the end of the file:

export PATH=$PATH:/usr/local/bin

Save the file and reload the shell configuration:

source ~/.bashrc

Verify the installation:

docker-compose —version

Adding Docker Compose to the PATH on Windows

Open System Properties:

  • Right-click on ‘This PC’ or ‘My Computer’ and select ‘Properties’.
  • Click on ‘Advanced system settings’.
  • Click on ‘Environment Variables’.

Edit the PATH variable:

  • In the ‘System variables’ section find and select the ‘Path’ variable then click ‘Edit’.
  • Click ‘New’ and add the path to the directory where docker-compose.exe is located.

Apply the changes and restart the Command Prompt or PowerShell:

docker-compose —version

Common Scenarios and Fixes

Scenario 1: Docker Compose Not Installed

Issue: If Docker Compose is not installed on the system attempting to the run docker-compose commands will result in a «command not found» error.

Solution:

Install Docker Compose: The Download and install Docker Compose from the official Docker documentation or package manager appropriate for the operating system.

Visit Docker Compose Installation Documentation for the installation instructions specific to the OS.

Example: Installing Docker Compose on Linux using curl:

sudo curl -L "https://github.com/docker/compose/releases/download/{version}/docker-compose-$(uname -s)-$(uname -m)"
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Scenario 2: Docker Compose Not in PATH

Issue: Even after installation if Docker Compose is not added to the system’s PATH variable the command-line interface won’t locate it.

Solution:

Update PATH Environment Variable: Ensure the directory where docker-compose is installed is added to the PATH.

On Linux, edit ~/.bashrc or ~/.bash_profile and add:

export PATH=$PATH:/usr/local/bin/docker-compose

The Source the file or restart the terminal for changes to take effect:

source ~/.bashrc

Scenario 3: Docker Compose Version Mismatch

Issue: Sometimes, if there’s a version mismatch or an outdated version of the Docker Compose commands might fail to the execute properly.

Solution:

Check Docker Compose Version: Ensure we are using the compatible version with Docker and the Docker environment.

Verify the installed Docker Compose version:

docker-compose --version

Update Docker Compose if necessary:

sudo curl -L "https://github.com/docker/compose/releases/download/{latest_version}/docker-compose-$(uname -s)-$(uname -m)" 
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Conclusion

We can successfully fix the «Docker Compose Command Not Found» error by attending to these common scenarios and implementing the suggested fixes. A development or production environment can execute Docker Compose commands more efficiently if it is installed correctly added to the PATH environment variable, and kept up to date.

The “docker command not found” error is a common issue encountered by users trying to run Docker commands on their systems. This error can arise from several causes, including incorrect installation, misconfigured paths, or even permissions issues. 

This article provides comprehensive steps for troubleshooting across different operating systems, ensuring that you can get Docker up and running again.

When you try to execute a Docker command, such as docker version, and encounter the error message:

bash: docker: command not found

This means that your system’s shell cannot locate the Docker executable. This article will walk through solutions to address this issue on different operating systems.

Why Is the Docker Command Not Found? 

How to Fix ‘Docker Command Not Found’?

Below are three methods that you can use to fix the ‘Docker Command Not Found’ error. 

Method 1: Checking Docker Installation

Before trying other troubleshooting steps, it would be wise to check whether or not you have a proper Docker installation done on your device. 

Linux

The first step is to check whether Docker is installed on your system. Run the following command:

dpkg -l | grep docker

If Docker is installed, you should see a list of installed Docker packages. If not, you need to install Docker.

Linux

How to Install Docker Using Command? 

If Docker is not installed, you can install it using the following commands:

sudo apt update

sudo apt install docker.io

sudo systemctl start docker

sudo systemctl enable docker

Here, 

  • sudo apt update updates the package list.
  • sudo apt install docker.io installs Docker.
  • sudo systemctl start docker starts the Docker service.

  • sudo systemctl enable docker enables Docker to start at boot.

After installation, check the Docker version to confirm:

docker —version

You should see the installed version of Docker.

macOS

On macOS, Docker is typically installed via Docker Desktop. Open Docker Desktop and check if it is running. If Docker Desktop is not installed, download it from the Docker website and follow the installation instructions.

Open a terminal and run:

docker —version

This should display the installed version of Docker.

Windows

On Windows, Docker is usually installed through Docker Desktop for Windows. Open Docker Desktop to ensure it is running.

If not installed, download Docker Desktop for Windows from the Docker website and install it.

Open Command Prompt or PowerShell and run:

docker —version

This should display Docker’s installed version.

Method 2: Checking System PATH

The PATH environment variable tells the shell where to look for executables. If Docker’s path is not included, it will result in the “command not found” error.

Linux

1. Check Docker Path:

Run the following command to find the Docker executable:

which docker

If this returns no output, Docker is not in your PATH.

2. Add Docker to PATH:

Find the directory where Docker is installed (usually /usr/bin/docker or /usr/local/bin/docker) and add it to your PATH.

Open your shell configuration file (e.g., ~/.bashrc, ~/.bash_profile, or ~/.zshrc) and add:

export PATH=$PATH:/usr/bin/docker

‘export PATH=$PATH:/usr/bin/docker’ appends Docker’s installation directory to the PATH variable.

3. Reload the Configuration:

Apply the changes:

source ~/.bashrc

macOS

  1. Find Docker Path:

Use the following command to locate Docker:

which docker

2. Update PATH:

Add Docker’s directory to the PATH in your shell configuration file (~/.bash_profile or ~/.zshrc):

export PATH=$PATH:/usr/local/bin/docker

3. Apply Changes:

Refresh the configuration:

source ~/.bash_profile

Windows

On Windows, Docker’s executable path should be automatically added to the system PATH during installation. If not, you can add it manually.

1. Find Docker Path:

Locate Docker’s installation directory, typically:

C:\Program Files\Docker\Docker\resources\bin

2. Update System PATH:

Go to System Properties > Advanced > Environment Variables.

Under System Variables, find and edit the Path variable.

Add Docker’s directory path.

3. Restart the Command Prompt:

Close and reopen the Command Prompt to apply changes.

Method 3: Permissions Issues

Sometimes, the Docker command may not work due to insufficient permissions, especially on Linux systems.

Linux

  1. Check Docker Group:

Ensure your user is part of the docker group:

sudo groupadd docker

sudo usermod -aG docker $USER

sudo groupadd docker creates a Docker group.

sudo usermod -aG docker $USER adds your user to the Docker group.

2. Restart Session:

Log out and back in, or restart the system to apply changes.

Verify Docker Access:

Run a Docker command without ‘sudo’:

docker ps

This should display the running containers, indicating permission is correctly set.

macOS and Windows

Permissions issues are less common on macOS and Windows, as Docker Desktop manages them. However, ensure you run terminal sessions with sufficient privileges.

Frequently Asked Questions

Can I run Docker on Windows without Docker Desktop?

Docker Desktop is the recommended way to run Docker on Windows, as it provides a seamless integration with Windows environments. Alternatives like Docker Toolbox are outdated and not recommended.

Do I need sudo to run Docker commands?

On Linux, Docker commands often require sudo unless your user is added to the Docker group. Use sudo usermod -aG docker $USER to add your user to the Docker group and avoid using sudo.

Conclusion

The “docker command not found” error is typically resolved by ensuring Docker is installed, configured in the system PATH, and placing appropriate permissions. If you have any questions or need further assistance, feel free to reach out in the comments or consult the official Docker documentation for more information.

  • Install and configure Ubuntu WSL
  • Install application
  • Docker in Windows without Docker Desktop
  • Docker/Kubernetes Clients
  • Git tricks

See items marked with ❤️‍🔥 to use winning variants

❤️‍🔥 Way 1. Using original docker binaries

Install docker client in Windows

  • Download necessary version of docker binaries from https://docs.docker.com/engine/install/binaries/ and extract archive to c:/Program Files, for example, using script in powershell. Run powershell as Administrator and call:

    Expand-Archive .\docker-20.10.9.zip -DestianationPath $Env:ProgramFiles  

    Files docker.exe and dockerd.exe will be here c:/Program Files/docker/.

    We need only docker.exe and do not need dockerd.exe because it can start only Windows containers.
    To check it you can try to call as Admin dockerd.exe and then docker.exe pull ubuntu. Expected result:
    no matching manifest for windows/amd64 10.0.19043 in the manifest list entries

  • Add path c:/Program Files/docker to environment variable PATH. It could be done with this powershell script:

    [Environment]::SetEnvironmentVariable("Path",$env:Path + ";c:/Program Files/docker", "Machine")

❤️‍🔥 Install Docker Daemon in WSL

  • Install docker under Ubuntu WSL using these instructions https://docs.docker.com/engine/install/ubuntu/

  • To provide ability to call docker in WSL without sudo add current user to docker group

    sudo groupadd docker
    sudo usermod -aG docker $USER
  • Configure dockerd to run (one of)…

    👉 over http with access from Windows

    ⤵️ Edit /etc/profile

    function rundocker(){
      ## Use this variant in case when `localhostForwarding` in `/etc/wsl.conf` is unset or equal to `false`
      #DOCKER_HOST=`ifconfig eth0 | grep -E "inet ([0-9]{1,3}.){3}[0-9]{1,3}" | head -1 | awk '{ print $2 }'`
      DOCKER_HOST=localhost
      WIN_CLIENT="/mnt/c/Program Files/docker/docker.exe"
      "$WIN_CLIENT" context rm -f wsl > /dev/null
      "$WIN_CLIENT" context create wsl --description "dockerd in WSL" --docker "host=tcp://$DOCKER_HOST:2375"
      "$WIN_CLIENT" context use wsl
      sudo dockerd -H $DOCKER_HOST -H "unix:///var/run/docker.sock" --tls=false
    }
    export -f rundocker

    Details…

    ⚠️ Be aware of this warnings:

    Binding to IP address without --tlsverify is insecure and gives root access on this machine to everyone who has access to your network.  host="tcp://172.27.117.140:2375"
    Binding to an IP address, even on localhost, can also give access to scripts run in a browser. Be safe out there!  host="tcp://172.27.117.140:2375"
    

    ⤵️ ❤️‍🔥 Run docker daemon on Windows startup using Task Scheduler (taskschd.msc)

    $task = New-ScheduledTaskAction -Execute "C:\Windows\System32\wsl.exe" -Argument '-u root bash -c "(source /etc/profile && rundocker &) && sleep 10"'
    $trigger = New-ScheduledTaskTrigger -AtLogon
    $settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
    Register-ScheduledTask RunDocker -Action $task -Trigger $trigger -Settings $settings

    ⤵️ Run docker daemon on Windows startup using Startup folder

    Open Startup folder Win+R -> shell:common startup (usually C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp) and create .bat script with content

    C:\Windows\System32\wsl.exe g -u root bash -c "(source /etc/profile && rundocker &) && sleep 10"

    ⤵️ To stop docker daemon manually

    sudo kill $(ps faux | grep 'dockerd' | grep -vw grep | awk '{ print $2 }')

    ⤵️ To run docker daemon manually

    rundocker &
    

    👉 without access from Windows, using systemd

    ⚠️ this method raises questions. Firstly, I do not know how to get access from Windows, e.g. cmd.exe. Secondly, systemd is a kind of overhead.

    ⚠️ TBD try to enable systemd: https://youtu.be/DmfuJzX6vJQ?t=459

    ⤵️ Add systemd support (about script, about Linux Software Repository for Microsoft Products)

    wget --content-disposition \
    "https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
      
    chmod +x ./install-sg.sh
      
    # use here appropriate version from https://packages.microsoft.com/ubuntu/
    sed -i -E 's/(UBUNTU_VERSION)=".+"/\1=21.04/g' ./install-sg.sh
      
    ./install-sg.sh

    Then Exit the WSL terminal and shutdown the WSL env:

    To open a new WSL terminal with systemd enabled, run:

    Details…

    ⚠️ In you have an error like

    $ wsl genie -s
    Timed out waiting for systemd to enter running state.
    This may indicate a systemd configuration error.
    Attempting to continue.
    Failed units will now be displayed (systemctl list-units --failed):
      UNIT                       LOAD   ACTIVE SUB    DESCRIPTION
    ● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
    
    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.
    1 loaded units listed.
    

    then disable this service

    sudo systemctl mask systemd-remount-fs.service

    then wsl --shutdown and retry wsl genie -s

    ⚠️ In you have an error (reproduced in Ubuntu 21.10) like

    WARN[2021-11-05T17:20:57.078243654+04:00] grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock 0 }. Err :connection error: desc = "transport: Error while dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout". Reconnecting... module=grpc
    failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain: (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables): RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1
    (exit status 4))
    

    then switch from nf_tables to ip_tables (see link1, link2):

    $sudo rm -rd /var/run/docker*
    # Ubuntu 21.10 uses nf_tables intead of ip_tables
    $/sbin/iptables --version
    $/usr/sbin/iptables-legacy --version
    $ sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

    ⤵️ Run docker daemon on Windows startup using Task Scheduler (taskschd.msc)

    $task = New-ScheduledTaskAction -Execute "C:\Windows\System32\wsl.exe" -Argument 'genie -s'
    $trigger = New-ScheduledTaskTrigger -AtLogon
    $settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
    Register-ScheduledTask RunDocker -Action $task -Trigger $trigger -Settings $settings

    ⤵️ Run docker daemon on Windows startup using Startup folder

    Open Startup folder Win+R -> shell:common startup (usually C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp) and create .bat script with content

    C:\Windows\System32\wsl.exe genie -s

    ⤵️ How to run docker daemon manually

    C:\Windows\System32\wsl.exe genie -s
    

    👉 over https with access from Windows too

    TBD

    👉 over channels?

    TBD

Way 2. Using nerdctl from Rancher Desktop instead of docker

⚠️ this way is not completely functional. Firstly, I do knot know how to make docker available everywhere — not only in bash under WSL. Secondly, nerdctl is not docker, so it could bring unexpected problems (e.g. nerdctl does not have --ip param for nerdctl run, who knows what else difference exist). But Rancher Desktop can be used as separate container orchestrator.

⚠️ I run nerdctl -n docker run -p 3000:3000 grafana/grafana, checked and then stopped container via ctrl+c or stop. After it, I cannot run it again until rebooting.

  • Install Rancher Desktop
  • Run and choose some version of Kubernetes
  • Tick WSL Integration -> Ubuntu. Link /home/<wsl-user>/.kube/config -> /mnt/c/Users/<win-user>/.kube/config will be created.
  • This step is required if you are using appendWindowsPath=false
    mkdir -p ~/.local/bin
    WIN_USER=<type-him>
    ln -s /mnt/c/Users/$WIN_USER/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/nerdctl.exe /home/$USER/.local/bin/nerdctl
    #ln -s /mnt/c/Users/$WIN_USER/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/kubectl.exe /home/$USER/.local/bin/kubectl
    #ln -s /mnt/c/Users/$WIN_USER/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/helm.exe /home/$USER/.local/bin/helm
    #ln -s /mnt/c/Users/$WIN_USER/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/kuberlr.exe /home/$USER/.local/bin/kuberlr
    #ln -s /mnt/c/Users/$WIN_USER/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/kim.exe /home/$USER/.local/bin/kim
    source ~/.bashrc

    Thereby nerdctl will be available in WSL for current user. Also you can link programs to /usr/bin/nerdctl to share it for all users.

  • Lets create alias docker -> nerdctl with hardcoded namespace name (in Rancher Desktop) where all images will be pull in. Add to ~/.bash_aliases or /etc/aliases:
    #nerdctl as docker
    alias docker='nerdctl -n docker'  

    Thereby nerdctl can be used as docker but this is possible only in bash under WSL (think about how to make link or script to fix parameter).

❤️‍🔥 Docker Compose

sudo apt-get install -y python3 python3-pip
pip3 install --user docker-compose

⚠️ Do not forget to set variable DOCKER_HOST in ~/.bashrc if it has not still done.

export DOCKER_HOST=tcp://localhost:2375

⚠️ On error TypeError: load_config() got an unexpected keyword argument 'config_dict' try to call scripts:

pip3 uninstall docker-compose
pip3 uninstall docker-py docker
pip3 install --user -U docker-compose

See also link1, link2, link3

See Setting Up Docker for Windows and WSL to Work Flawlessly

☢️ Problem with host.docker.internal

I caught error Error: net::ERR_CONNECTION_REFUSED at http://host.docker.internal:6006?path=... with docker-chromium having run under jet-puppeteer-docker in Jetbrains Idea (only there).
The only way to fix it was found:

  • Install Docker Desktop and clone folder c:\Program Files\Docker as c:\Program Files\Docker_. After that Docker Desktop can be removed.
  • Then make steps above to unpack binaries. Then copy with a replace files docker.exe and com.docker.cli.exe from c:\Program Files\Docker_\Docker\resources\bin\ to c:\Program Files\Docker.
  • I do not know why it is so. Despite docker.exe is just client to dockerd in WSL, but it makes some difference. When we use not-patched version of docker.exe then /etc/hosts does not contains needed alias. But when we use patched version of docker.exe from Docker Desktop (with required com.docker.cli.exe) then it gets OK. I suggested that a problem is hidden in difference of versions and checked it. Probably, Nope.
    • Docker 20.10.10, build b485636 from Docker Desktop
    • Docker 20.10.9, build c2ea9bc from binaries
    • Docker 20.10.10, build b485636 from binaries
  • At the same time do not touch docker-compose.exe, leave original version

  • 1 Overview
  • 2 System requirements
  • 3 Install Docker
  • 4 Run Docker
    • 4.1 CMD
    • 4.2 Powershell
    • 4.3 Bash on Windows

Overview

This is a quick tutorial how to install Docker on Windows and use it via CMD or Bash on Windows (Linux subsystem for Windows — WSL). It is assumed that the reader has basic knowledge of the Windows command line (CMD) and, if Bash should be used, a basic familiarity with Bash on Ubuntu on Windows. We will demonstrate a basic example to run a docker image.

System requirements

For detailed system requirements, see What to know before you install but main requirements are

  • Hyper-V running/enabled (note that this means that VirtualBox VM images won’t run anymore and there may be other implications for high-precision applications, see details at Introduction to Hyper-V on Windows 10)
  • 64bit Windows 10 Pro/Education/Enterprise (there are people claiming Docker runs on Windows 10 Home but we found this not to be true when trying ourselves as Hyper-V seems only available for Pro, Education and Enterprise versions — 1511 November update, Build 10586 or later), see also official Microsoft page on Hyper-V system requirements at Install Hyper-V on Windows 10. Windows >= 8 may work as well but we haven’t tested it.
  • Virtualization must be enabled

Install Docker

The installation is best performed by using officially provided binary installer from Docker webpage. We recommend the stable version unless you need latest changes from development version. Once the installation is through (and PC restarted) Docker should be automatically running indicated by its icon showing in the task bar.

In case it is not running for you, one reason might be that the automatic enabling of Hyper-V during the Docker installation did not work. Check the official Microsoft page on Hyper-V at Install Hyper-V on Windows 10 to see a couple of ways to enable it. Also note that Hyper-V activation and virtualization activation are not the same thing so make sure virtualization is enabled in BIOS, too (usually the case if you used virtual machines before, e.g. via VirtualBox). See how to enable it at Step-By-Step: Enabling Hyper-V for use on Windows 10.

You can also check Hyper-V status on a detailed level via Powershell using below (run as admin)

Get-WindowsOptionalFeature -Online -FeatureName *hyper*

Run Docker

Docker can be run in a few ways, we show it via CMD, Powershell and Bash on Windows. In general, CMD and Powershell usage should be fairly similar but you may require some additional wrangling for Bash. If you used the official Windows binary installer from the Docker webpage, the relevant path/environment variables should already be set and you can start using it right away. As opposed to running Docker on Linux, Windows should not require running the terminal as admin.

CMD

Check if Docker works by testing below examples. Note that you require an internet connection in case you have never used below Docker images before (e.g. hello-world) as Docker will automatically download/pull those.

docker --version
docker run hello-world

Finally you can run a more demanding example by running a Linux Ubuntu Bash terminal (this may take some time depending on your bandwidth as the complete Ubuntu image is pulled). Note that you are made root user in the shell.

docker run -it ubuntu bash

Powershell

As CMD, Powershell should work out of the box so we only show the hello-world example here again. Note that the image is not pulled again as we had just used it before in CMD.

docker run hello-world

Bash on Windows

In general, Bash on Windows should inherit the PATH from Windows environment variables and thus work out of the box as well but there are a couple of things to note (note special care when working with WSL config files as outlined in subsection A general note of caution for Bash on Windows).

  • Windows binary installer sets PATH variable as C:\Program Files\Docker\Docker\Resources\bin although it should actually be C:\Program Files\Docker\Docker\resources\bin, i.e. lower case r in resources. This should generally not be an issue in case-insensitive Windows but may lead to issues in Linux (WSL) although we haven’t encountered any. Still you may want to adjust it.
  • We found that you get the error Unable to translate current working directory. Using C:\WINDOWS\system32 when running Docker in WSL in some directories, e.g. home (~), but not when running it in others, e.g. in /mnt/c/Program\ Files/Docker/Docker/resources/bin. This is apparently expected as some directories have no Windows equivalent, see this Github issue.
  • Docker on Windows comes as binary, i.e. docker.exe. To avoid extra typing and confusion you probably want to set an alias e.g. in your .bashrc file as so alias docker="docker.exe".

In case you find Docker not working with an error message like The program "docker" is currently not installed. You can install it by typing: sudo apt-get install docker it is probably caused by not having set the alias correctly or because Windows does not find Docker in the PATH. You can try pointing Windows to the Docker install by including it in the PATH via .bashrc as so PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin".

Finally, we run the same examples as with CMD (we spare you running an Ubuntu image from an Ubuntu system as WSL although it would be possible of course).

docker --version
docker run hello-world

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Самая легкая windows 7 embedded standard в 2021 году
  • Виртуальная машина windows на ubuntu server
  • Как выключить антивирус на windows 10 360 total security
  • Windows server 2008 sp2 x64 iso
  • Chip windows xp что это такое