一、系統環境
1.1 環境准備:
Windows10 企業版 1909
Docker for Windows
WSL Ubuntu18.04
1.2 下載安裝 Docker for Windows
1.3 打開Docker,在General中勾選中Expose eaemon on tcp://localhost:2375 without TLS
1.4 打開Microsoft Store,搜索Ubutun,選擇Ubutun18.04進行安裝
二、安裝Docker
以下內容來自Docker - 從入門到實戰 和 菜鳥教程 Docker 教程 Ubuntu安裝Dock
2.1 卸載舊版本
舊版本的 Docker 稱為 docker 或者 docker-engine ,使用以下命令卸載舊版
本:
$ sudo apt-get remove docker \
docker-engine \ docker.io
2.2 更新包索引
$ sudo apt-get update
2.3 設置國內源
推薦中國科技大學的源,穩定速度
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list sudo apt update
2.4 使用 APT 安裝
由於 apt 源使用 HTTPS 以確保軟件下載過程中不被篡改。因此,我們首先需要
添加使用 HTTPS 傳輸的軟件包以及 CA 證書。
$ sudo apt-get install \
apt-transport-https \ ca-certificates \ curl \ software-properties-common
為了確認所下載軟件包的合法性,需要添加軟件源的 GPG 密鑰。
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ gpg | sudo apt-key add -
更新包緩存。
$ sudo apt-get update
2.5 安裝 Docker CE
$ sudo apt-get install docker-ce
2.6 啟動 Docker CE
$ sudo systemctl enable docker
$ sudo systemctl start docker
2.7 測試啟動Docker
$ docker run hello-world
若能正常輸出以下信息,則說明安裝成功。
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world d1725b59e92d: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9f de470971e499788 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: The Docker client contacted the Docker daemon. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64) The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. The Docker daemon streamed that output to the Docker client,which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
2.8 建立 docker 用戶組
默認情況下, docker 命令會使用 Unix socket 與 Docker 引擎通訊。而只有root 用戶和 docker 組的用戶才可以訪問 Docker 引擎的 Unix socket。出於安全考慮,一般 Linux 系統上不會直接使用 root 用戶。因此,更好地做法是將需要使用 docker 的用戶加入 docker 用戶組。
建立Docker用戶組
$ sudo groupadd docker
添加當前用戶到 docker 用戶組
$ sudo usermod -aG docker $USER
三、安裝過程中遇到的問題
3.1 安裝后無法啟動hello-world的問題
安裝完成后運行 docker run hello-world 時出現“docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.”的提示,找了很多資料說是服務沒有啟動,要不就是其他的問題,處理后還是問題依舊。后來查到 windows10 linux子系統 ubuntu 18.0運行docker 這篇文章,里面給出了正確的解決方式。就是要設置 1.3 的操作,然后再運行
$ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
$ source ~/.bashrc
然后就可以正常使用了。
