Docker private warehouse, volume, port mapping

Private Warehouse Establishment
To build a private warehouse
(1) Download the registry image at the character terminal
(2) The client sets the daemon.json file to specify the private warehouse location
(3) Generate registry container, open 5000 ports
(4) Image labeling: docker tag original image name warehouse IP: port / image name (must be labeled)
(5) Upload image: docker push warehouse IP: port / image name
(6) Download Image: docker pull warehouse IP: port / image name (view with docker images)

Build private warehouse

[root@docker ~]# docker pull registry
[root@docker ~]# vim /etc/docker/daemon.json 
{
  "insecure-registries": ["192.168.7.168:5000"],    //Use "," between different parameter options
  "registry-mirrors": ["https://syy5204b.mirror.aliyuncs.com"]
}
[root@docker ~]# systemctl restart docker
[root@docker ~]# docker run -d -p 5000:5000 -v /data/registry:/tpm/registry registry
#/ data/registry in the host will automatically create / tpm/registry in the mount container
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4e3029f01510        registry            "/entrypoint.sh /etc..."   4 seconds ago       Up 4 seconds        0.0.0.0:5000->5000/tcp   eager_northcutt
[root@docker ~]# docker pull nginx 
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              e791337790a6        About an hour ago   127MB
[root@docker ~]# docker tag nginx:latest 192.168.7.168:5000/nginx
[root@docker ~]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
192.168.7.168:5000/nginx   latest              e791337790a6        2 hours ago         127MB
[root@docker ~]# docker push 192.168.7.168:5000/nginx
#Get list of private warehouses
curl -XGET http://192.168.7.168:5000/v2/_catalog
{"repositories":["nginx"]}
[root@docker ~]# docker rmi 192.168.7.168:5000/nginx:latest 
[root@docker ~]# docker pull 192.168.7.168:5000/nginx
Using default tag: latest
latest: Pulling from nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 192.168.7.168:5000/nginx:latest
192.168.7.168:5000/nginx:latest
[root@docker ~]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
192.168.7.168:5000/nginx   latest              e791337790a6        2 hours ago         127MB

Docker data volume
docker data volume is the storage space of the host system by mounting

[root@docker ~]# docker pull centos
#/ data1 in the host directory / var/www / Mount container
#These directories do not need to be created manually, and will be created automatically
[root@docker ~]# docker run -v /var/www:/data1 --name test1 -it centos /bin/bash
[root@3ea73938c9b5 /]# cd /data1/
[root@3ea73938c9b5 data1]# touch test123
#Return to the host for viewing
[root@docker ~]# ls /var/www/
test123

Docker data volume container
Storage space of Mount container

#Create data volume container
[root@docker ~]# docker run --name web100 -v /data1 -v /data2 -it centos /bin/bash
[root@44c8fbe8e01a /]# ls
bin    data2  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
data1  dev    home  lib64  media       opt  root  sbin  sys  usr
#New container mount data volume container web100
[root@docker ~]# docker run -it --volumes-from web100 --name db1 centos /bin/bash
[root@9b0b7f686192 /]# ls
bin    data2  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
data1  dev    home  lib64  media       opt  root  sbin  sys  usr
#Create a file in a new container and view the same content in the data volume container

Port mapping

#Do not specify port
[root@docker ~]# docker run -d -P nginx
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                     NAMES
6dd91cea1325        nginx               "nginx -g 'daemon of..."   4 seconds ago       Up 4 seconds                  0.0.0.0:1234->80/tcp      eager_mclean
#Specify port
[root@docker ~]# docker run -d -p 1234:80 nginx
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                     NAMES
fd952499c2c5        nginx               "nginx -g 'daemon of..."   8 seconds ago       Up 7 seconds                  0.0.0.0:32768->80/tcp     infallible_beaver
  • -P: Specify random mapping port
  • -p: Mapping on fixed IP address
    Container interconnection (using centos image)
    #Create and run the container named web1, and automatically map the port number
    [root@docker ~]# docker run -itd -P --name web1 centos /bin/bash
    #Create and run the container named web2, and associate web1
    [root@docker ~]# docker run -itd -P --name web2 --link web1:web1 centos /bin/bash
    #You can ping web1 directly in web2
    [root@docker ~]# docker exec -it 3c0d72923de3 /bin/bash
    [root@3c0d72923de3 /]# ping web1
    PING web1 (172.17.0.5) 56(84) bytes of data.
    64 bytes from web1 (172.17.0.5): icmp_seq=1 ttl=64 time=0.200 ms
    64 bytes from web1 (172.17.0.5): icmp_seq=2 ttl=64 time=0.110 ms

Keywords: Linux Docker Nginx CentOS JSON

Added by serg91 on Thu, 23 Apr 2020 18:15:23 +0300