docker 私有仓库建立,容器卷挂载
一、仓库
1.代码仓库:公共仓库github ,私有仓库gitlib
2.镜像仓库:公共仓库 docker hub ,私有仓库:registry(有图像终端界面)harbor(字符终端界面)
二、registry私有仓库建立步骤
设立私有仓库后下载镜像时优先寻找私有仓库镜像内容
1.拉取镜像文件
docker pull registry
2.修改docker引擎终端配置
[root@localhost ~]#vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.190.11:5000"],
"registry-mirrors": ["https://45htmp62.mirror.aliyuncs.com"]
}
:wq
systemctl restart docker.service
3.创建registry容器并挂载宿主机目录
docker create -it registry /bin/bash
docker ps -a
docker start 84eab70a2490 #这样开启容器会失败
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry #可以使用该条命令挂载卷,run=pull+create+start
4.更改标识并上传本地的一个镜像文件
docker images
docker tag nginx:test 192.168.190.11:5000/nginx
docker push 192.168.190.11:5000/nginx
5.获取镜像列表
curl -XGET http://192.168.190.11:5000/v2/_catalog
---------输出信息----------
[root@localhost ~]#curl -XGET http://192.168.190.11:5000/v2/_catalog
{"repositories":["nginx"]}
6.测试私有仓库下载
docker rmi 192.168.190.11:5000/nginx #删除已有的镜像
docker pull 192.168.190.11:5000/nginx #指定镜像名称
三、docker数据卷
挂载到宿主机目录中
格式:docker run -v 宿主机目录:容器内目录 -it 镜像 /bin/bash #目录不存在的话自动创建
docker run -v /var/www:/data1 --name web1 -it centos /bin/bash
[root@d58e644c2f7b /]# cd /data1
[root@d58e644c2f7b data1]# touch test1
四、容器数据卷(两个容器的交互目录挂载)
格式:docker run --volumes-from 另外的容器 -it 镜像 /bin/bash
docker run --name web1 -v /data1 -v /data2 -it centos /bin/bash
docker run --name web2 --volumes-from web1 -itd centos /bin/bash
五、容器互联
在容器和接受容器间建立一条网络通讯隧道
docker run -itd -P --name web1 centos /bin/bash
docker run -itd -P --name web2 --link web1:web1 centos /bin/bash
--------验证-------
#进入一个容器ping另一个容器
[root@localhost ~]#docker exec -it 974077bf71df /bin/bash
[root@974077bf71df /]# ping web1
PING web1 (172.17.0.3) 56(84) bytes of data.
64 bytes from web1 (172.17.0.3): icmp_seq=1 ttl=64 time=0.157 ms
64 bytes from web1 (172.17.0.3): icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from web1 (172.17.0.3): icmp_seq=3 ttl=64 time=0.069 ms
^C