2019-07-01 Ubuntu 安装Docker

如果安装了旧版本(可能是docker或docker-engine),先卸载掉。

sudo apt remove docker
sudo apt remove docker-engine
sudo apt remove docker.io
#或者写成
sudo apt remove docker \
                docker-engine \
                docker.io

然后安装https支持及CA证书

sudo apt update
sudo apt upgrade 
sudo apt install apt-transport-https ca-certificates curl software-properties-common

添加软件源的GPG密钥

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

# 向source.list中添加Docker软件源
 $ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

安装Docker CE

sudo apt update
sudo apt install docker-ce

使用脚本自动安装

curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh 
#想使用国内阿里源加上mirror
sudo sh get-docker.sh --mirror Aliyun

使用脚本完成安装后,就可以启动了

sudo systemctl start docker
sudo systemctl enable docker

建立docker用户组,加入当前用户

sudo groupadd docker
sudo usermod -aG docker $Username

测试下docker安装运行正常,有类似以下输出说明ok了。

axing@axtest99:~$ docker run hello-world

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/

你可能感兴趣的:(2019-07-01 Ubuntu 安装Docker)