ubuntu日常Linux研究linux&github

win10设置docker在wsl下使用

2019-01-15  本文已影响523人  7cf6c01a5633

背景

由于 Docker daemon无法在wsl下运行,但是可以连接到远程的daemon服务,比如docker-for-windows. 所以就可以在windows上体验linux的开发环境,并使用docker在搭建开发环境了。

安装docker for window

  1. 下载安装, 按照提示一步一步来,很简单。
    2

安装ubuntu的镜像

  1. 在win10商店中安装ubuntu
  2. 打开ubuntu,安装docker-cli, docker-compose
# Update the apt package list.
sudo apt-get update -y

# Install Docker's package dependencies.
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# Download and add Docker's official public PGP key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.
#
# If you want to live on the edge, you can change "stable" below to "test" or
# "nightly". I highly recommend sticking with stable!
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Update the apt package list (for the new apt repo).
sudo apt-get update -y

# Install the latest version of Docker CE.
sudo apt-get install -y docker-ce

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $USER

# Install Python and PIP.
sudo apt-get install -y python python-pip

# Install Docker Compose into your user's home directory.
pip install --user docker-compose

配置docker

  1. 允许远程连接docker


    docker-for-windows-expose-daemon-without-tls.jpg
  2. 设置ubuntu链接远程docker daemon

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
  1. 验证是否工作正常
# You should get a bunch of output about your Docker daemon.
# If you get a permission denied error, close + open your terminal and try again.
docker info

# You should get back your Docker Compose version.
docker-compose --version
  1. 设置ubuntu的磁盘映射路径,docker需要的路径是/c/Users/nick/dev/myapp, 实际上的挂在路径是/mnt/c/Users/nick/dev/myapp
sudo nano /etc/wsl.conf # 这个文件可能不存在

# Now make it look like this and save the file when you're done:
[automount]
root = /
options = "metadata"
  1. 然后重启就可以了

参考

  1. setting-up-docker-for-windows-and-wsl-to-work-flawlessly
上一篇下一篇

猜你喜欢

热点阅读