Docker——私有仓库、数据卷、端口映射、容器互联

news/2024/7/5 13:16:22

文章目录

  • 私有仓库简易版registry建立
  • Dockers数据卷和数据卷容器
    • 数据卷创建
    • 数据卷容器创建
  • 端口映射
  • 容器互联

私有仓库简易版registry建立

仓库镜像

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
ddad3d7c1e96: Pull complete 
6eda6749503f: Pull complete 
363ab70c2143: Pull complete 
5b94580856e6: Pull complete 
12008541203a: Pull complete 
Digest: sha256:bac2d7050dc4826516650267fe7dc6627e9e11ad653daca0641437abdf18df27
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

查看下载的镜像
在这里插入图片描述
指定私有仓库的位置

[root@localhost ~]# vim /etc/docker/daemon.json 

{
  "insecure-registries": ["192.168.80.10:5000"],
  "registry-mirrors": ["https://i657xnlq.mirror.aliyuncs.com"]
}

创建私有仓库容器

[root@localhost ~]# docker create -it registry /bin/bash
6c38f03cf0ee7854d77e48fd66d22e4aae90ab934984523ecdd52f95eba19742
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                                     NAMES
6c38f03cf0ee   registry     "/entrypoint.sh /bin…"   4 seconds ago    Created                                                   gracious_jemison

启动registry容器

[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
6cbbade6496071273c715b70e35be1026db6dd8eab88ff3e8ccf0a6ee8766679

  • -d 守护进程
  • -p 端口 5000:5000 前者为对外提供的端口,后者为内部端口
  • -v 指卷轴的挂载 ,挂在信息为 宿主机上/data/registry目录共给registry容器 的/tmp/registry 目录使用
  • 构建容器的时候使用-v 挂载 外部的路径是会自动生成的。不需要先行创建
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE        COMMAND                  CREATED              STATUS              PORTS                                       NAMES
6cbbade64960   registry     "/entrypoint.sh /etc…"   About a minute ago   Up About a minute   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   affectionate_bhaskara
6c38f03cf0ee   registry     "/entrypoint.sh /bin…"   4 minutes ago        Created                                                         gracious_jemison

下载nginx、定义标签(必须修改)

[root@localhost ~]# docker pull nginx 
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
[root@localhost ~]# docker tag nginx:latest 192.168.80.10:5000/nginx

192.168.80.10为私有仓库所在服务器的IP ,5000为对外提供的端口 nginx为镜像名称
上传镜像

[root@localhost ~]# docker push 192.168.80.10:5000/nginx
Using default tag: latest
The push refers to repository [192.168.80.10:5000/nginx]
075508cf8f04: Pushed 
5c865c78bc96: Pushed 
134e19b2fac5: Pushed 
83634f76e732: Pushed 
766fe2c3fc08: Pushed 
02c055ef67f5: Pushed 
latest: digest: sha256:61191087790c31e43eb37caa10de1135b002f10c09fdda7fa8a5989db74033aa size: 1570

查看私有仓库信息

[root@localhost ~]# curl -XGET http://192.168.80.10:5000/v2/_catalog
{"repositories":["nginx"]}

删除原有的nginx镜像,尝试从私有仓库中下载

[root@localhost ~]# docker images
REPOSITORY   TAG        IMAGE ID       CREATED        SIZE
tomcat       new        60c44f97a1b8   24 hours ago   964MB
registry     latest     1fd8e1b0bb7e   7 weeks ago    26.2MB
centos       7          8652b9f0cb4c   6 months ago   204MB
centos       7.4.1708   9f266d35e02c   2 years ago    197MB

从私有仓库中下载

[root@localhost ~]# docker pull 192.168.80.10:5000/nginx
Using default tag: latest
latest: Pulling from nginx
69692152171a: Pull complete 
30afc0b18f67: Pull complete 
596b1d696923: Pull complete 
febe5bd23e98: Pull complete 
8283eee92e2f: Pull complete 
351ad75a6cfa: Pull complete 
Digest: sha256:61191087790c31e43eb37caa10de1135b002f10c09fdda7fa8a5989db74033aa
Status: Downloaded newer image for 192.168.80.10:5000/nginx:latest
192.168.80.10:5000/nginx:latest
[root@localhost ~]# docker images
REPOSITORY                 TAG        IMAGE ID       CREATED        SIZE
tomcat                     new        60c44f97a1b8   24 hours ago   964MB
192.168.80.10:5000/nginx   latest     d1a364dc548d   8 days ago     133MB
registry                   latest     1fd8e1b0bb7e   7 weeks ago    26.2MB
centos                     7          8652b9f0cb4c   6 months ago   204MB
centos                     7.4.1708   9f266d35e02c   2 years ago    197MB

Dockers数据卷和数据卷容器

  • 数据卷:挂载宿主系统的存储空间
  • 数据卷容器:挂载容器的存储空间(也可以实现容器之间文件的共享)

数据卷创建

格式:docker run -v 宿主机挂载点 -name 容器名 -it 镜像名

[root@localhost ~]# docker run -v /var/www:/data1 --name web11 -it centos:7 /bin/bash
[root@95e5537331bc /]# ls
anaconda-post.log  data1  etc   lib    media  opt   root  sbin  sys  usr
bin                dev    home  lib64  mnt    proc  run   srv   tmp  var
[root@95e5537331bc data1]# touch test1
[root@95e5537331bc data1]# ls
test1

启动另一个终端查看是否有/var/www/test1文件

[root@localhost ~]# cd /var/www/
[root@localhost /var/www]# ls
test1

数据卷容器创建

先创建可以被挂载的容器

[root@localhost ~]# docker run --name web100 -v /data1 -v /data2 -it centos:7 /bin/bash
[root@9fd8780c6ca2 /]# ls
anaconda-post.log  data1  dev  home  lib64  mnt  proc  run   srv  tmp  var
bin                data2  etc  lib   media  opt  root  sbin  sys  usr

另起一个终端,创建新的容器,指定挂载的web100容器
并在容器的/data1和/data2各新建一个文件

[root@localhost ~]# docker run -it --volumes-from web100 --name db1 centos:7 /bin/bash
[root@8b3f8e83994f /]# cd data1
[root@8b3f8e83994f data1]# touch demo01
[root@8b3f8e83994f data1]# cd ../data2
[root@8b3f8e83994f data2]# touch demo02
[root@8b3f8e83994f data2]# 

在钱一个终端中查看

[root@9fd8780c6ca2 /]# cd data1
[root@9fd8780c6ca2 data1]# ls   
demo01
[root@9fd8780c6ca2 data1]# cd ../data2
[root@9fd8780c6ca2 data2]# ls
demo02

端口映射

-P随机生成端口号

[root@localhost ~]# docker run -d -P httpd:latest 
58dffe19aad7f2a9ffa4e9f22982d21ff06c4b2c28306716fe56146d456ed676
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                      PORTS                                       NAMES
58dffe19aad7   httpd:latest   "httpd-foreground"       6 seconds ago    Up 5 seconds                0.0.0.0:49153->80/tcp, :::49153->80/tcp     gallant_payne

-p指定端口号

[root@localhost ~]# docker run -d -p 333:80 httpd:latest 
ad7d9969e1dc6d414c858fd34332222e4562fb92958781af828fd7114d75a4cb
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                      PORTS                                       NAMES
ad7d9969e1dc   httpd:latest   "httpd-foreground"       5 seconds ago    Up 4 seconds                0.0.0.0:333->80/tcp, :::333->80/tcp         admiring_lalande

容器互联

创建并运行web1容器,端口号自动映射

[root@localhost ~]# docker run -itd -P --name web1 centos:7 /bin/bash
eae9a331a7366840a58312c985f5101edd34c34bb7862e39bfe640cbf6560729
[root@localhost ~]# docker run -itd -P --name web2 --link web1:web1 centos:7 /bin/bash
c265541f2b822431d5e8ea3bd81145451104951ef374acff4acd2fedef4bbea3
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                      PORTS                                       NAMES
c265541f2b82   centos:7       "/bin/bash"              5 seconds ago    Up 5 seconds                                                            web2
eae9a331a736   centos:7       "/bin/bash"              34 seconds ago   Up 33 seconds                                                           web1

进入web2容器 ping web1

[root@localhost ~]# docker exec -it c265541f2b82 /bin/bash
[root@c265541f2b82 /]# 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.330 ms
64 bytes from web1 (172.17.0.5): icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from web1 (172.17.0.5): icmp_seq=3 ttl=64 time=0.056 ms
64 bytes from web1 (172.17.0.5): icmp_seq=4 ttl=64 time=0.056 ms
64 bytes from web1 (172.17.0.5): icmp_seq=5 ttl=64 time=0.071 ms


http://www.niftyadmin.cn/n/3652476.html

相关文章

[介绍]PHP设计模式:DAO(数据访问对象模式)

from url: http://www.phppatterns.com/docs/design/data_access_object_pattern_more_widgets?sdaoTired of writing the same SQL statements over and over again? The Data Access Object pattern provides a useful way to abstract data fetching operations. In this …

Docker容器——compose

文章目录Docker Compose简介YAML格式使用步骤Docker compose配置常用字段Docker compose常用命令docker compose 命令参数详解编排实验环境部署构建nginxDocker Compose 简介 Docker Compose前身是Fig,Fig被Docker收购之后正式更名为Compose,Compose向…

HTTP:错误码

1xx-信息提示 表示临时的响应。客户端在收到常规响应之前,应准备接收一个或多个1xx响应。  100-继续。  101-切换协议。  2xx-成功 表明服务器成功地接受了客户端请求。  200-确定。客户端请求已成功。  201-已创建。  202-已接受。  203-非权威性信息。  2…

Docker----Consul介绍与安装

文章目录consul简介特点实验搭建server部署 192.168.80.10client部署 192.168.80.20配置template模块自动更新配置template测试测试访问代理服务器再添加一个节点consul简介 Consul是一个分布式、高可用的系统,是一个为了解决在生产环境中服务注册,服务…

某著名门户网站搜索部门笔试中的逻辑题

某著名门户网站搜索部门笔试中的逻辑题,如果能够做出来,我想逻辑思维和数学水平应该都不错。(做题前不要去搜索答案,不然就不能考验出自己的逻辑能力了,呵呵)1. 打牌,没有大小王,只有…

[转]MySQL5.1新特性翻译系列 - 通过分区(Partition)提升MySQL性能

来源:http://phpv.net/article.php/1514MySQL5.1新特性翻译系列 - 通过分区(Partition)提升MySQL性能几年前,俺写过一篇题为“The Foundation of Excellent Performance”的文章(现在仍然可以在http://www.tdan.com/i016fe03.htm看…

[转]Berkeley DB 数据库的优缺点

Berkeley DB 数据库的优缺点来源:http://www.nowboy.com/main/archives/52BDB官方网站:http://www.sleepycat.com/Sleepycat软件公司出品的Berkeley DB是一种在特定的数据管理应用程序中广泛使用的数据库系统,在世界范围内有超过两亿的用户支持.许多世界…

Docker----Harbor的介绍和安装

文章目录简介Harbor架构即组件介绍Harbor配置文件以及相关参数搭建Harbor私有仓库1、搭建环境2、下载Harbor安装程序3、配置Harbor参数文件4、启动Harbor5、浏览器访问UI界面创建项目6、在本地测试仓库功能7、客户端上传镜像维护管理Harbor1、停止Harbor实例2、修改Harbor.cfg配…