- 安装docker
使用官方脚本安装
curl -fsSL https://get.docker.com | bash -s docker
也可以指定国内镜像安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
安装完成后,启动docker
systemctl start docker
- 配置docker远程访问
修改 /lib/systemd/system/docker.service文件,修改配置为
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
修改之前的文件
修改之后的文件
加载配置文件并重启docker
systemctl daemon-reload && systemctl restart docker
- 验证是否开启远程访问
本机 docker images 查看镜像文件
远程机器 docker images 查看镜像文件
使用命令 docker -H tcp://${remote_ip}:2375 images
经验证本机与远程查看的结果一致!
- 搭建docker私有镜像仓库
拉取镜像
docker pull registry
创建容器
docker run -d -p 5000:5000 --name registry docker.io/registry
访问 http://${server_ip}:5000/v2/_catalog
如果无法访问:执行 systemctl daemon-reload && systemctl restart docker 再访问
正常访问结果
推送镜像到仓库中
以推送hello-world镜像为例
本地拉取 hello-world镜像
docker pull hello-world:latest
对 hello-world 打上标签
docker tag hello-world:latest 127.0.0.1:5000/hello-world:latest
推送镜像
docker push 127.0.0.1:5000/hello-world:latest
推送结果:显示推送成功
查看仓库,hello-world已经存在于仓库中