搭建docker私有镜像仓库
搭建私有镜像仓库
环境准备:192.168.8.246(docker仓库服务器) 192.168.8.245(节点服务器)
1安装软件docker-distribution,并且设置为开机自启状态并且现在是开机状态
2查看配置文件/etc/docker-distribution/registry/config.yml(不需要修改)
工作目录是哪,默认端口5000
3测试 curl http://IP:5000/v2/_catalog
上传镜像到私有镜像仓库
1所有节点都要有此文件(指定私有镜像仓库) 创建文件vim /etc/docker/daemon.json
- {
- "exec-opts": ["native.cgroupdriver=systemd"],
- "registry-mirrors": ["https://hub-mirror.c.163.com"],
- "insecure-registries":["192.168.1.100:5000", "registry:5000"]
- }
上传镜像
1打标签:docker tag 旧标签 新标签(打完可以查看一下镜像,是否有新的标签镜像生成)
docker tag nginx:latest 192.168.8.246:5000/nginx:latest
2节点进行上传 docker push 192.168.1.100:5000/busybox:latest
[root@source docker]# docker push 192.168.8.246:5000/nginx:latest
The push refers to repository [192.168.8.246:5000/nginx]
89decbdf7fb7: Pushed
787822cf1b17: Pushed
3c816b4ead84: Pushed
latest: digest: sha256:f630aa07be1af4ce6cbe1d5e846bb6bb3b5ba6bfec0ec0edc08ba48d8c1d9b0f size: 948
[root@source docker]#
#仓库检查是否上传到仓库
[root@localhost ~]# curl http://192.168.8.246:5000/v2/_catalog
{"repositories":["nginx"]}
下载镜像(没有的镜像从私有镜像仓库下载)
docker pull 192.168.8.246:5000/mysql:5.7
docker pull 192.168.8.246:5000/nginx:latest
1指定私有镜像仓库,重启docker(清空容器)
2 docker run -it 192.168.1.100:5000/myos:latest(在执行的时候自动下载)
一个没有任何镜像 的节点可以先制定私有镜像仓库的地址,然后直接从私有镜像地址里的仓库去获取镜像,有了私有镜像地址很方便,不用到处去找镜像
坑:防火墙和selinux导致到镜像仓库网络不通
删除镜像
[root@source ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 1ba37a28a83f 2 days ago 445MB
centos 7 eeb6ee3f44bd 20 months ago 204MB
[root@source ~]# docker images centos:7
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 20 months ago 204MB
[root@source ~]# docker image rm centos:7
Untagged: centos:7
Untagged: centos@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
[root@source ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 1ba37a28a83f 2 days ago 445MB
[root@source ~]# docker image rm 1ba
Error response from daemon: conflict: unable to delete 1ba37a28a83f (must be forced) - image is being used by stopped container 796f2b67ad8e
[root@source ~]# docker stop 796f2b67ad
796f2b67ad
[root@source ~]# docker image rm 1ba
Error response from daemon: conflict: unable to delete 1ba37a28a83f (must be forced) - image is being used by stopped container 796f2b67ad8e
[root@source ~]# docker stop 796f2b67ad
796f2b67ad
[root@source ~]# docker rm 796
796
[root@source ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@source ~]# docker ps -a -q
[root@source ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
将镜像导入到本地
[root@source ~]# docker load -i docker_mysql5.7.tar.gz
ad6b69b54919: Loading layer [==================================================>] 72.55MB/72.55MB
fba7b131c5c3: Loading layer [==================================================>] 338.4kB/338.4kB
0798f2528e83: Loading layer [==================================================>] 9.556MB/9.556MB
a0c2a050fee2: Loading layer [==================================================>] 4.202MB/4.202MB
d7a777f6c3a4: Loading layer [==================================================>] 2.048kB/2.048kB
0d17fee8db40: Loading layer [==================================================>] 53.77MB/53.77MB
aad27784b762: Loading layer [==================================================>] 5.632kB/5.632kB
9b64bb048d04: Loading layer [==================================================>] 3.584kB/3.584kB
35ba198e64f5: Loading layer [==================================================>] 313.2MB/313.2MB
789f3aa31b3f: Loading layer [==================================================>] 17.92kB/17.92kB
e889c671872c: Loading layer [==================================================>] 1.536kB/1.536kB
Loaded image: mysql:5.7