安装Docker的方式有很多种
apt、snap、yum 等等
但是最简单的 同时也是兼容操作系统最多的方式来自于 rancher 团队
以下是 19.03 和 20.10 的例子
sudo curl https://releases.rancher.com/install-docker/19.03.sh | sh
sudo curl https://releases.rancher.com/install-docker/20.10.sh | sh
下一步就是让非root用户能够调用 docker 命令
老版本的这个 sh 会提示你输入
sudo usermod -aG docker ubuntu
然后重启动 docker,并且重新登录用户就可以了
最新版本的这个提示换了
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
直接使用
dockerd-rootless-setuptool.sh install
会提示
########## BEGIN ##########
sudo sh -eux <<EOF
# Install newuidmap & newgidmap binaries
apt-get install -y uidmap
EOF
########## END ##########
运行之后就没问题了
然后设置一个环境变量
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock
使用 apt 安装的方式
sudo apt install docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker ubuntu
reboot