Docker环境搭建

Docker搭建
https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

阿里云Docker环境加速
https://yq.aliyun.com/articles/543028

原文地址 http://www.runoob.com/docker/ubuntu-docker-install.html

Ubuntu 18.04 安装 Docker-ce

1.更换国内软件源,推荐清华tuna

参考 https://mirrors.tuna.tsinghua.edu.cn/help/debian/
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

更改源,然后sudo apt update
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free

2.安装需要的包

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

3.添加 GPG 密钥,并添加 Docker-ce 软件源,这里还是以中国科技大学的 Docker-ce 源为例

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

4.添加成功后更新软件包缓存

sudo apt update

5.安装 Docker-ce

sudo apt install docker-ce

6.设置开机自启动并启动 Docker-ce(安装成功后默认已设置并启动,可忽略)

sudo systemctl enable docker
sudo systemctl start docker

7.测试运行

sudo docker run hello-world

8.添加当前用户到 docker 用户组,可以不用 sudo 运行 docker(可选)

sudo groupadd docker
sudo usermod -aG docker $USER

9.测试添加用户组(可选)

docker run hello-world

发表评论