1.安装docker 使用官方脚本安装
curl -fsSL https://get.docker.com | bash -s docker
安装完成后,启动
docker systemctl start docker
2. 配置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
3.验证是否开启远程访问
本机 docker images 查看镜像文件
出现问题不能访问官方docker
修改访问阿里云docker-hub
cd /etc/docker/
vi daemon.json
#在文件中输入以下内容并保存
{
"registry-mirrors":[
"https://kfwkfulq.mirror.aliyuncs.com",
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
] }
加载配置文件并重启docker
systemctl daemon-reload && systemctl restart docker
[root@localyum docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
4. 搭建docker私有镜像仓库
拉取镜像
docker pull registry
[root@localyum docker]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
31e352740f53: Pull complete
7f9bcf943fa5: Pull complete
3c98a1678a82: Pull complete
51f7a5bb21d4: Pull complete
3f044f23c427: Pull complete
Digest: sha256:9977826e0d1d0eccc7af97017ae41f2dbe13f2c61e4c886ec28f0fdd8c4078aa
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localyum docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 4bb5ea59f8e0 4 days ago 24MB
创建容器
docker run -d -p 5000:5000 --name registry docker.io/registry
[root@localyum docker]# docker run -d -p 5000:5000 --name registry docker.io/registry
cea7662d5a13ae4a75c372524bfb09fc9811b0d8c19e943ebba2f924e5f45ad5
[root@localyum docker]#
访问 http://10.18.109.9:5000/v2/_catalog
如果无法访问:执行 systemctl daemon-reload && systemctl restart docker 或 docker start registry 再访问
正常访问结果
推送镜像到仓库中
以推送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
推送结果:显示推送成功