原博客地址 https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
1. Install Docker on Windows
To install the Docker engine on Windows, just go to docker.com and download the appropriate distribution. Also, make sure hardware virtualization is enabled and Hyper-V is installed, lest the engine won’t start.
Shortcut: Install Windows 10 Creators Update
With Windows 10 Creators Update, accomplishing all of this has become a lot simpler, since it allows you to run Windows executables from Bash. Just add these two lines to your .bashrc
(and reload your environment) and you’re done!
export PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin"
alias docker=docker.exe
alias docker-compose=docker-compose.exe
1 2 3 4 |
export PATH="$HOME/bin:$HOME/.local/bin:$PATH" export PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin" alias docker=docker.exe alias docker-compose=docker-compose.exe |
You can now run docker --version
from Bash, and you don’t even have to read the rest of this blog post :)
Making it work on Windows 10 Anniversary Edition
To install Docker on the WSL, you’ll need to jump through a few more hoops. There’s a description for Ubuntu in general here, which works for the WSL as well, with the exceptions of some of the optional steps. Here’s what I did:
# Install packages to allow apt to use a repository over HTTPS
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# Add Docker‘s official GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Set up the repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Update source lists
sudo apt-get update
# Install Docker
sudo apt-get install docker-ce
1 2 3 4 5 6 7 8 9 10 |
# Install packages to allow apt to use a repository over HTTPS $ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common # Add Docker‘s official GPG key $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # Set up the repository sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Update source lists sudo apt-get update # Install Docker sudo apt-get install docker-ce |
Of course, there’s also the option of downloading and extracting the binaries we’ll need, and put them somewhere in your PATH
. There are instructions here for how to get the latest version.
Where did that get us?
We now actually have the Docker engine installed on both Windows and the WSL, but it isn’t started on either. The Windows installer helpfully created a Docker shortcut on the desktop and/or in the Start menu – use that to start the Docker engine. Then, you can try running e.g. docker images
from PowerShell and from Bash:
PowerShell:
PS C:\> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1 2 |
PS C:\> docker images REPOSITORY TAG IMAGE ID CREATED SIZE |
We haven’t created any images yet, so that’s fine.
原文地址:https://www.cnblogs.com/nhz-M/p/11044665.html