Docker安装配置
作者:Meow时间:2025-01-21 10:29:14分类:技术
系统为Ubuntu24,配置过程参考了菜鸟教程:
下载官方的安装脚本:
curl -fsSL https://test.docker.com -o test-docker.sh
给脚本赋予可执行权限:
sudo chmod +x test-docker.sh
运行脚本:
sudo sh test-docker.sh
试运行hello world,这里一般会报错(由于众所周知的网络原因):
sudo docker run hello-world
运行结果:Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers). See 'docker run --help'.
需要配置daemon文件,填写其他的镜像网站:
vim /etc/docker/daemon.json
将一下内容粘贴上去:
{
"registry-mirrors":
[
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]
}
重新读取daemon文件,并重启docker服务,然后再次测试hello world:
systemctl daemon-reload
systemctl restart docker.service
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:1b7a37f2a0e26e55ba2916e0c53bfbe60d9bd43e390e31aacd25cb3581ed74e6 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
成功了!
--------------------------------------------------------------------------------
对于需要用到多容器集群的项目,需要用到docker-compose,从github下载:
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
并赋予可执行权限:
sudo chmod +x /usr/local/bin/docker-compose
最后查看是否安装成功:
docker-compose -v