Ubuntu16.04安装docker环境

1.先卸载可能存在的旧版本,并更新软件包
sudo apt-get remove docker docker-engine docker-ce docker.io
sudo apt-get update

2.安装需要的依赖包
sudo apt install apt-transport-https ca-certificates software-properties-common curl

3.添加GPG密钥,需指定源

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

sudo add-apt-repository "deb [arch=amd64,arm64] 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
sudo docker run hello-world

参考网址:
https://zhuanlan.zhihu.com/p/88351963
http://t.zoukankan.com/loveyoul9-p-11438627.html

7.验证docker中使用NVIDIA显卡
sudo apt-get install nvidia-container-runtime

which nvidia-container-runtime-hook

docker run -it --rm --name test --gpus all ubuntu:latest

docker run -itd --gpus all --name 容器名 -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all 镜像名

参考网址:
https://blog.csdn.net/weixin_43590796/article/details/114848742
https://www.jianshu.com/p/8f38a63b86cc


8.添加docker源
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}

systemctl restart docker
参考网址:
https://www.csdn.net/tags/Ntjakg3sMjIzMC1ibG9n.html
https://blog.csdn.net/qq_37189082/article/details/100047697

9.解决WARING:No swap limit support
用sudo docker info查看docker安装信息,结果显示WARNING: No swap limit support

sudo vim /etc/default/grub
找到GRUB_CMDLINE_LINUX=配置项,原有的内容切记不要删除,在双引号内添加cgroup_enable=memory swapaccount=1,与原来的内容之间用空格分隔。

sudo update-grub

reboot

参考网址:
https://blog.csdn.net/qq_41821301/article/details/105243294

10.当要以非root用户可以直接运行docker时,需要执行 sudo usermod -aG docker localhost 命令,然后重新登陆
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
newgrp docker #更新用户组
docker ps #测试docker命令是否可以使用sudo正常使用

参考网址:
https://blog.csdn.net/weixin_42447403/article/details/123796067
https://www.cnblogs.com/javalinux/p/16479832.html
http://edu.jb51.net/docker/docker-ubuntu-docker-install.html

11.ubuntn为普通用户添加sudo权限

# 为用户username添加sudo权限
sudo usermod -a -G sudo username

# 去除用户username的sudo权限
sudo usermod -G usergroup username

参考网址:
https://blog.csdn.net/Strive_For_Future/article/details/114047990

posted @ 2022-11-03 09:27  盛夏夜  阅读(150)  评论(0编辑  收藏  举报