Ubuntu安裝docker/docker-compose(在全新系統狀態下的安裝)

設置倉庫

更新 apt 包索引。

$ sudo apt-get update

安裝 apt 依賴包,用於通過HTTPS來獲取倉庫:

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

添加 Docker 的官方 GPG 密鑰:

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 通過搜索指紋的後8個字元,驗證您現在是否擁有帶有指紋的密鑰。

$ sudo apt-key fingerprint 0EBFCD88


    pub   rsa4096 2017-02-22 [SCEA]
          9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
    uid           [ unknown] Docker Release (CE deb) <[email protected]>
    sub   rsa4096 2017-02-22 [S]

使用以下指令設置穩定版倉庫

$ sudo add-apt-repository \
   "deb [arch=amd64] //mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(lsb_release -cs) \
  stable"

安裝 Docker Engine-Community

更新 apt 包索引。

$ sudo apt-get update

安裝最新版本的 Docker Engine-Community 和 containerd

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

測試 Docker 是否安裝成功,輸入以下指令,列印出以下資訊則安裝成功:

$ sudo docker run hello-world
Unable to find image
'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f 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: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. 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/

安裝 Docker-Compose

docker-compose的安裝不推薦pip安裝,無論如何都會失敗,用以下官方提供的方法,最後一條指令返回docker-compose的版本資訊:

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

docker pull鏡像加速源配置,docker-compose和docker共用一個,下列命令行執行完後直接重啟docker服務,如果docker鏡像下載速度緩慢,則重新啟動系統可解決這個問題

$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF' 
{
  "registry-mirrors": ["//fudfkcar.mirror.aliyuncs.com"]
}
EOF

至此安裝docker與docker-compose完成,現在可享用docker

docker的安裝採摘自://www.runoob.com/docker/ubuntu-docker-install.html