[實作筆記]在 Windows Subsystem for Linux 執行 docker

前情提要

最近開始學 Docker, 這個神器大概在 C 社時期就有聽過了,
不過一直沒有機會在實務上接觸,雖然有自已摸一點,但就只有皮毛而已,
在 A 社有機會由同事開課,並提供 EC2 作實驗,就趁這個機會作一點深入的學習。

一開始有一個很天真的想法,我想在 Windows 內建的 Linux 子系統 Ubantu 安裝 Docker
沒想到最後是脫褲子放屁,不過過程蠻有趣的,稍微記錄一下。

操作步驟

  1. Windows 10 安裝 Ubantu

  2. 在 Ubantu 安裝 Docker

    更新 apt-get

    1
    sudo apt-get update

    允許 apt-get 透過 https

    1
    2
    3
    4
    5
    sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

    加入 Docker 官方 GPG KEY

    1
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    然後可以驗証一下

    1
    sudo apt-key fingerprint 0EBFCD88

    加入 Docker 的 apt-repository

    1
    2
    3
    4
    $ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

    再次更新 apt-get

    1
    sudo apt-get update

    安裝 Docker CE

    1
    sudo apt-get install docker-ce
  3. Run Docker

1
sudo docker container run hello-world

我都會失敗如下

1
2
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

如何解決

  1. Windows 上要安裝 Docker for Windows

  2. 勾選 Docker for Windows → Setting → Expose Daemon on tcp://localhost:2375 Without TLS
    Docker

  3. 回到 Ubantu , 執行以下命令

指定 Docker Host 在路徑

1
docker -H localhost:2375 images

如果不想每次指定的話…請參考以下命令

1
export DOCKER_HOST=localhost:2375

執行結果

學到的事

參考

(fin)

Please enable JavaScript to view the Gitalk. :D
Please enable JavaScript to view the LikeCoin. :P
Please enable JavaScript to view the LikeCoin. :P