Centos下 安装docker并搭建自己的docker仓库

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
推送结果:显示推送成功 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值