Ubuntu 如何搭建docker?
官网地址 https://docs.docker.com/engine/install/ubuntu/
1、OS requirements 确认操作系统的版本
2022年8月29日查看官网,现阶段支持的版本有
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Impish 21.10
- Ubuntu Focal 20.04 (LTS)
- Ubuntu Bionic 18.04 (LTS)
2、Uninstall old versions 卸载旧的版本
sudo apt-get remove docker docker-engine docker.io containerd runc
3、Installation methods 安装方式,本文选择在线安装
3.1 Update the apt
package index and install packages to allow apt
to use a repository over HTTPS: 更新apt
sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
3.2 Add Docker’s official GPG key: 添加Docker的官方密钥
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3.3 Use the following command to set up the repository: 设置储存库
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3.4 Install Docker Engine: 安装docker
sudo apt-get update # 一定要再更新一次 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
4、测试一下
docker version
成功的截图
5.建议增加权限,否则每次都要用sudo 来执行
sudo usermod -aG docker $USER sudo reboot
6.运行一个hello world
docker run hello-world
7.更新docker源
因为默认是国外的地址,很慢,建议加上国内的
sudo vim /etc/docker/daemon.json ####加入下面内容#### { "registry-mirrors": [ "https://hub-mirror.c.163.com", "https://mirror.baidubce.com" ] }
7.1.重新启动服务
sudo systemctl daemon-reload sudo systemctl restart docker
7.2检验
docker info
出现下面这个就是成功!
扩展:如果 docker version 出现下面错误
需要增加当前用户到docker用户组 add the user to the docker group.
sudo usermod -aG docker $USER sudo reboot
参考资料
https://docs.docker.com/engine/install/ubuntu/
https://stackoverflow.com/questions/51342810/how-to-fix-dial-unix-var-run-docker-sock-connect-permission-denied-when-gro
https://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html
配置镜像加速 https://yeasy.gitbook.io/docker_practice/install/mirror
扩展书籍《Docker技术入门与实战》:
https://yeasy.gitbook.io/docker_practice/install/ubuntu