docker安裝(記錄)

0. 機器環境

ubuntu 16.04

CE(社區版)docker

1. 設置docker倉庫

sudo apt-get update

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

# 添加 docker 官方 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88
# 確認輸出有 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

# 設置倉庫
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

2. 安裝docker

sudo apt-get update

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

# 列出可以安裝的版本
apt-cache madison docker-ce

# 安裝指定版本
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
# 例如這裏選擇版本 5:18.09.1~3-0~ubuntu-xenial

# 驗證是否安裝成功
sudo docker run hello-world

顯示如下則表示安裝成功:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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/


 

3. 遇到的問題

3.1 ModuleNotFoundError: No module named 'apt_pkg'

import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

解決辦法:

sudo apt-get remove --purge python-apt
sudo apt-get install python-apt -f 
cd /usr/lib/python3/dist-packages/ 
sudo cp apt_pkg.cpython-3?m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so 

3.2 每次輸入都需要輸入 sudo

  • 如果還沒有 docker group 就添加一個:

    sudo groupadd docker
  • 將用戶加入該 group 內。然後退出並重新登錄就生效啦。

    sudo gpasswd -a ${USER} docker
  • 重啓 docker 服務

    sudo service docker restart
  • 切換當前會話到新 group 或者重啓

    newgrp - docker
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章