文章目录
- 1. Docker是什么
- 2. Docker下载
- 3 一些小坑
- 4 参考文档:
1. Docker是什么
Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
2. Docker下载
2.1 确认版本
- 确认操作系统对应版本。
在官网查看自己需要的操作系统对应的Docker版本。
2. 确认自己的操作系统版本符合docker要求的版本号,比如说:Ubuntu里面要求的版本是下面这几个
3 一些小坑
3.1 版本号添加
包含<> 进行替换。举个例子:
sudo apt-get install docker-ce=5:20.10.17~3-0~ubuntu-focal docker-ce-cli=5:20.10.17~3-0~ubuntu-focal containerd.io docker-compose-plugin
报错:invoke-rc.d: could not determine current runlevel
报错位置
sudo apt-get install docker-ce=5:20.10.17~3-0~ubuntu-focal docker-ce-cli=5:20.10.17~3-0~ubuntu-focal containerd.io docker-compose-plugin
解决方案
查看自己的OS和版本是否符合官方文档中的要求,不符合的更换OS。
笔者原来的是
不符合官网的要求,后来换成了
成功下载。
报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
报错位置
运行时下列代码时报错
sudo docker run hello-world
解决方案
先看安装情况
docker version
结果
错误消息提示:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
原来是没有运行,docker启动命令
sudo service docker start #命令行
* Starting Docker: docker #提示信息
报错:Unable to find image ‘hello-world:latest’ locally
报错位置
再次运行命令:
sudo docker run hello-world
弹出消息:
Unable to find image ‘hello-world:latest’ locally
docker: Error response from daemon: Head “https://registry-1.docker.io/v2/library/hello-world/manifests/latest”: net/http: TLS handshake timeout.
See ‘docker run --help’.
大概意思是运行时拉取不到hello-world这个镜像报错。
解决方案
增加新镜像
sudo vim /etc/docker/daemon.json
新添加文本内容
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
重新启动docker
sudo service docker restart #Windows下WSL2子系统运行命令
#或者Linux下命令
systemctl restart docker
重新执行命令
sudo docker run hello-world
报错:System has not been booted with systemd as init system (PID 1). Can’t operate.
报错位置
在Windows下wsl2使用Linux子系统中调用了 systemctl 命令
解决方案
应该使用 service 命令
4 参考文档:
4.1 docker安装踩坑
侵删请联系笔者
版权声明:本文为Srwici原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。