文章目录
- Docker Registry
- Docker Registry Command
- Image Command
- Nginx
- Nginx System install
- Nginx Config
- Container Command
- Create My Degistry
- BusyBox
- 腾讯云镜像仓库搭建
Docker Registry
镜像仓库负责存储、管理、分发镜像,并且提供了登录认证的能力,建立仓库索引
镜像仓库管理多个Repository(存储库),Repository通过命名来区分。每个Repository包含一个或者多个镜像,镜像通过镜像名称和标签(Tag)来区分
镜像仓库分类和工作机制
分类:按照是否对外开放划分,共有仓库(放在共有网络上,不用登录就可以下载镜像),私有仓库(不对外开放,往往位于私有网络,只有公司内部人员可以使用)
工作机制:通过docker login登录仓库, docker pull拉去镜像, 通过dockerfile或者commit方式制作完镜像通过docker push上传到仓库
常用镜像仓库
Docker Hub: https://hub.docker.com/
Docker Registry Command
命令 | 别名 | 功能 | 备注 |
---|---|---|---|
docker login | 登录仓库 | 重要 | |
docker pull | docker image pull | 拉取镜像 | 重要 |
docker push | docker image push | 推送镜像 | 重要 |
docker search | 查找镜像 | ||
docker logout | 登出仓库 | 重要 |
拉取镜像
下载方式1: Tag 标签下载
下载方式2: 名字+编号下载
docker pull nginx@sha256:a97a153152fcd6410bdf4fb64f5622ecf97a753f07dcc89dab14509d059736cf
创建仓库推送镜像
仓库创建成功后,会告诉我们Push的格式
docker push chinamaxxin/mynginx:tagname
# 原来的tag为 nginx:1.23.4
# 需要改成 chinamaxxin/mynginx:v1.23.4# 使用docker tag 更改标签
[root@VM-20-6-centos ~]# docker tag nginx:1.23.4 chinamaxxin/mynginx:v1.23.4
[root@VM-20-6-centos ~]# docker push chinamaxxin/mynginx:v1.23.4 # 将其推送到仓库
The push refers to repository [docker.io/chinamaxxin/mynginx]
4d33db9fdf22: Mounted from library/nginx
6791458b3942: Mounted from library/nginx
2731b5cfb616: Mounted from library/nginx
043198f57be0: Mounted from library/nginx
5dd6bfd241b4: Mounted from library/nginx
8cbe4b54fa88: Mounted from library/nginx
v1.23.4: digest: sha256:a97a153152fcd6410bdf4fb64f5622ecf97a753f07dcc89dab14509d059736cf size: 1570
# 之后在网站上就可以看到我们上传的镜像了
我们还可以使用 docker push 其它选项,如
docker push chinamaxxin/mynginx -a
就会将所有前缀为chinamaxxin/mynginx
的镜像推送到对应仓库
查找镜像
[root@VM-20-6-centos ~]# docker search -f stars=10 nginx
# -f starts=10 选项设置条件,收藏量大于10
Docker Server上的镜像信息比较少,查看不方便,推荐官网搜索,所以docker search指令并不常用
Image Command
docker images
docker images [options][repository[:tag]] # 列出本地镜像
docker image list # 别名
-a # 列出本地所有镜像(含中间映像层,默认过滤)
--digests # 显示镜像摘要信息
-f # 显示满足条件的镜像
--format # 指定返回值的模板文件
--no-trunc # 显示完整的镜像信息
-q # 只显示镜像ID
docker image inspect
docker image inspect [option] # 查看镜像详细信息
@example
[root@VM-20-6-centos ~]# docker image inspect nginx:1.23.4
[root@VM-20-6-centos ~]# docker image inspect a7be6198544f
docker tag
# 使用docker tag 更改标签
[root@VM-20-6-centos ~]# docker tag nginx:1.23.4 chinamaxxin/mynginx:v1.23.4
Nginx
Nginx时一款自由开源高性能的HTTP反向代理服务器,Nginx可以作为一个HTTP服务器进行网站发布处理,还可以作为反向代理进行负载均衡实现。Nginx是web服务器的一种实现
前置概念
正向代理
由于防火墙原因,我们不能直接访问外网,但是我们可以使用VPN来进行实现。VPN就是一个简单正向代理的例子。正向代理的是"客户端",VPN帮助客户端将流量送出去。
客户端知道目标IP,而目标并不知道客户IP,保护客户信息
反向代理
当我们访问百度时,实际上我们的请求会被转发,被百度的反向代理服务器代理到百度的内网去。我们并不知道我们实际访问的信息是来自百度哪一台存储服务器。这一过程对于用户来说是透明的。同时我们通过反向代理服务器实现流量分配,构建基于负载均衡的服务器集群
客户端知道反向代理服务器IP,并不知道服务器IP,保护了服务器
Nginx System install
卸载
# 卸载Nginx
[root@VM-20-6-centos ~]# ps -ef | grep nginx | grep -v grep
# 因为目前没有安装所以没有输出,若存在nginx服务需要对其master进程关闭
[root@VM-20-6-centos ~]# kill [nginx_master_process pid][root@VM-20-6-centos ~]# rpm -qa | grep nginx # 查看通过yum源安装的nginx信息
[root@VM-20-6-centos ~]# yum remove nginx # 使用yum卸载nginx
安装
# 配置yum源
[root@VM-20-6-centos ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # 新配置yum源会被放到/etc/yum.repos.d/目录下
[root@VM-20-6-centos ~]# ls /etc/yum.repos.d/
CentOS7-Base-163.repo Centos-7.repo CentOS-SCLo-scl.repo CentOS-SCLo-scl-rh.repo docker-ce.repo epel-7.repo epel.repo epel-testing.repo nginx.repo repo_bak# 构建缓存加速下载,配置文件有点多就不复制了
[root@VM-20-6-centos ~]# yum makecache [root@VM-20-6-centos ~]# yum install nginx -y
启动
# 检查是否启动,没有输出说明没有启动
[root@VM-20-6-centos ~]# ps -ef | grep nginx | grep -v grep# 方法1: 使用systemctl start 指令
[root@VM-20-6-centos ~]# systemctl start nginx
[root@VM-20-6-centos ~]# ps -ef | grep nginx | grep -v grep
root 21319 1 0 13:27 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 21320 21319 0 13:27 ? 00:00:00 nginx: worker process
nginx 21321 21319 0 13:27 ? 00:00:00 nginx: worker process# 方法2:输入nginx
# 杀死master进程,关闭nginx服务
[root@VM-20-6-centos ~]# kill 21319
[root@VM-20-6-centos ~]# ps -ef | grep nginx | grep -v grep
# 直接输入nginx即可启动
[root@VM-20-6-centos ~]# nginx
[root@VM-20-6-centos ~]# ps -ef | grep nginx | grep -v grep
root 21935 1 0 13:29 ? 00:00:00 nginx: master process nginx
nginx 21936 21935 0 13:29 ? 00:00:00 nginx: worker process
nginx 21937 21935 0 13:29 ? 00:00:00 nginx: worker process
输入IP地址即可访问服务器上的Nginx了
Nginx Config
Nginx配置信息放在/etc/nginx/nginx.conf文件中
# 此处删除部分内容
[root@VM-20-6-centos nginx]# cat nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {worker_connections 1024;
}
http {include /etc/nginx/conf.d/*.conf; # 仅需要关注这个就好了
}
# include 就像C++中包的头文件一样,会将该路径下文件内容进行展开
# 进入上述文件夹,可以查看到更多http服务相关文件
[root@VM-20-6-centos nginx]# cd conf.d/
[root@VM-20-6-centos conf.d]# ll
total 4
-rw-r--r-- 1 root root 1072 Apr 12 01:21 default.conf
[root@VM-20-6-centos conf.d]# ll
total 4
-rw-r--r-- 1 root root 1072 Apr 12 01:21 default.conf# 查看默认配置文件
[root@VM-20-6-centos conf.d]# cat default.conf
server { # 类型: HTTP服务器listen 80; # 监听HOST_IP:80端口server_name localhost;#access_log /var/log/nginx/host.access.log main;location / { # 访问根目录时root /usr/share/nginx/html; # 首页index index.html index.htm; }# 访问首页#[root@VM-20-6-centos html]# cat /usr/share/nginx/html/index.html#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}
}
Container Command
docker run
docker run [options] image [command][arg...] # 创建一个新的容器并运行一个命令
-d # 后台运行容器,并返回容器ID
-i # 以交互模式运行容器,通常与 -t同时使用
-t # 为容器分配一个伪终端
-P # 随机端口映射,容器内部端口随机映射到主机端口
-p # 指定端口映射, 格式: 宿主端口:容器端口
--name="nginx-clx" # 指定容器名称
-h # 指定主机名称
-e # 指定环境变量
--cpuset-cpu="0-1" # 指定程序在哪个cpu上跑
-m # 指定该容器执行可以使用最大内存量
--link=[] # 添加连接到另外一个容器
--rm # shell退出时自动删除容器
docker run 无参运行
# 拉取一个CentOS7镜像
[root@VM-20-6-centos ~]# docker pull centos:7# 查看存在镜像
[root@VM-20-6-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chinamaxxin/mynginx v1.23.4 a7be6198544f 4 days ago 142MB
nginx 1.23.4 a7be6198544f 4 days ago 142MB
centos 7 eeb6ee3f44bd 20 months ago 204MB
nginx 1.18.0-alpine 684dbf9f01f3 2 years ago 21.9MB# 无参运行docker run
[root@VM-20-6-centos ~]# docker run centos:7# docker ps 不带参看运行的容器
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# docker ps -a 将创建所有容器打出
[root@VM-20-6-centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96de16216bf2 centos:7 "/bin/bash" 8 seconds ago Exited (0) 7 seconds ago ecstatic_jang# 直接运行nginx镜像
[root@VM-20-6-centos ~]# docker run nginx:1.23.4
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
## 可以发现nginx将日志打印到终端上,并且占用终端(前台运行)### 新建终端,可以看到nginx容器正在运行
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf9a946259a1 nginx:1.23.4 "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp zealous_tharp#### 向前台发送2号(SIGINT)信号,nginx退出,说明前台程序会接收到我们给终端的信号
[root@VM-20-6-centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf9a946259a1 nginx:1.23.4 "/docker-entrypoint.…" 2 minutes ago Exited (0) 13 seconds ago zealous_tharp
96de16216bf2 centos:7 "/bin/bash" 7 minutes ago Exited (0) 7 minutes ago ecstatic_jang
-d 后台运行选项
# 让nginx容器后台运行,会返回容器ID
[root@VM-20-6-centos ~]# docker run -d nginx:1.23.4
3614902a95965c4b7566d6677c867254d46821777f0c5c999f2de54f60e68221
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3614902a9596 nginx:1.23.4 "/docker-entrypoint.…" 50 seconds ago Up 49 seconds 80/tcp distracted_wing
-P, -p 绑定端口选项
# 绑定容器80端口绑定宿主机80端口
[root@VM-20-6-centos ~]# docker run -d -p 80:80 nginx:1.23.4
ff7e117ad9b0e462d8f95107ffa693344dba469107d374502413a789f23f48f5## 出现报错,宿主机80端口被绑定
docker: Error response from daemon: driver failed programming external connectivity on endpoint kind_mclaren (0764542d7b2bd643405d9b16e7e95a881ff751764dc853a9aaa192e681f3b22b): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.### 查看宿主机80端口绑定信息,发现80端口已经被nginx进程占用
[root@VM-20-6-centos ~]# netstat -nltp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21935/nginx: master #### 修改绑定端口为8888 ,绑定成功
[root@VM-20-6-centos ~]# docker run -d -p 8888:80 nginx:1.23.4
940f69ec97d027766857e2b1bc234ea4affd797b46978ec47daedbc4a18f44a8##### 打印容器信息,POSTS字段标记端口绑定信息
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
940f69ec97d0 nginx:1.23.4 "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:8888->80/tcp, :::8888->80/tcp adoring_goldwasser
3614902a9596 nginx:1.23.4 "/docker-entrypoint.…" 9 minutes ago Up 9 minutes 80/tcp distracted_wing
通过访问宿主机的8888端口发现可以访问到容器的80端口以及服务
注意:使用端口时需要设置防火墙,若宿主机绑定端口被防火墙屏蔽,则任然无法访问
# 尝试-P选项
[root@VM-20-6-centos ~]# docker run -d -P nginx:1.23.4
1a7d988d88ba581a99267d760bd0323690a45eeaa958df1ea065a8162c8a3c2# 随机绑定到32768端口,此端口我们云服务器并未设置安全组进行开放,防火墙会对流量进行阻拦,所以浏览器无法访问
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a7d988d88ba nginx:1.23.4 "/docker-entrypoint.…" 9 seconds ago Up 8 seconds 0.0.0.0:32768->80/tcp, :::32768->80/tcp wonderful_zhukovsky
940f69ec97d0 nginx:1.23.4 "/docker-entrypoint.…" 5 minutes ago Up 5 minutes 0.0.0.0:8888->80/tcp, :::8888->80/tcp adoring_goldwasser
3614902a9596 nginx:1.23.4 "/docker-entrypoint.…" 13 minutes ago Up 13 minutes 80/tcp distracted_wing## 使用curl命令访问本机(本机访问本机无需经过防火墙), 可以观察到nginx首页面信息被获取成功
[root@VM-20-6-centos ~]# curl 127.0.0.1:32768
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
–name=“nginx-lb” 指定名容器名称
[root@VM-20-6-centos ~]# docker run -d --name="mynginx1" nginx:1.23.4
5ec5228ee71cbd1d45d425f8adbb2476d55ee00f46c9385f635621d104f0a84c
[root@VM-20-6-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ec5228ee71c nginx:1.23.4 "/docker-entrypoint.…" 6 seconds ago Up 4 seconds 80/tcp mynginx1 ## 可以看到名称被设置
1a7d988d88ba nginx:1.23.4 "/docker-entrypoint.…" 8 minutes ago Up 8 minutes 0.0.0.0:32768->80/tcp, :::32768->80/tcp wonderful_zhukovsky
940f69ec97d0 nginx:1.23.4 "/docker-entrypoint.…" 13 minutes ago Up 13 minutes 0.0.0.0:8888->80/tcp, :::8888->80/tcp adoring_goldwasser
3614902a9596 nginx:1.23.4 "/docker-entrypoint.…" 22 minutes ago Up 22 minutes 80/tcp distracted_wing# 可以根据名字来停止容器,进行交互等
[root@VM-20-6-centos ~]# docker stop mynginx1
mynginx1
-h 参数指定hostname
# 不指定hostname可以看到,随机生成的主机名很纯
[root@VM-20-6-centos ~]# docker run -it centos:7 bash
[root@7a0f83cf2aae /]# hostname
7a0f83cf2aae# 使用-h 指定hostname执行bash
[root@VM-20-6-centos ~]# docker run -it -h mycentos7 centos:7 bash
[root@mycentos7 /]# hostname
mycentos7
-e 参数指定环境变量
[root@VM-20-6-centos ~]# docker run -it -h mycentos7 -e myenv=test centos:7 bash
[root@mycentos7 /]# env | grep myenv
myenv=test
–cpuset-cpus=“0-1” 指定程序使用CPU权限
## 查看机器CPU信息
[root@VM-20-6-centos /]# cat /proc/cpuinfo[root@VM-20-6-centos ~]# docker run -d --name mynginx1 --cpuset-cpus="0-1" nginx:1.24.0 # 设置该容器只能在CPU 0 和 1上跑## mynginx1容器名已经存在
docker: Error response from daemon: Conflict. The container name "/mynginx1" is already in use by container "5ec5228ee71cbd1d45d425f8adbb2476d55ee00f46c9385f635621d104f0a84c". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
## 注意:在docker中已经停止的容器名也会被占用[root@VM-20-6-centos /]# docker run -d --name mynginx2 --cpuset-cpus="0-1" nginx:1.24.0
585684512bae49591b1762acee8d60809efe77a319eadeb4bccac48e1c3fdfe6
-m 指定程序使用内存最大量
# 新建两个容器,一个不设置内存上限,另一个设置为500m
[root@VM-20-6-centos /]# docker run -d --name="mynginx3" nginx:1.24.0
5127e5c566d19e0e3a1300c0354c8edeb4430f85b21991c6b7223b2bb968ff3d
[root@VM-20-6-centos /]# docker run -d --name="mynginx4" -m 500m nginx:1.24.0
d97cc43588f9baeeea6fd0c334a42c842702f9fe1e672a96fcaa03dad6f01db9# docker stats 监视docker容器使用情况
[root@VM-20-6-centos ~]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d97cc43588f9 mynginx4 0.00% 2.008MiB / 500MiB 0.40% 586B / 0B 0B / 4.1kB 3
5127e5c566d1 mynginx3 0.00% 2.012MiB / 3.608GiB 0.05% 656B / 0B 0B / 4.1kB 3
585684512bae mynginx2 0.00% 2.477MiB / 3.608GiB 0.07% 656B / 0B 0B / 8.19kB 3
2dff8650b925 cranky_pascal 0.00% 412KiB / 3.608GiB 0.01% 710B / 0B 0B / 0B 1
1a7d988d88ba wonderful_zhukovsky 0.00% 2.035MiB / 3.608GiB 0.06% 1.3kB / 1.23kB 0B / 4.1kB 3
940f69ec97d0 adoring_goldwasser 0.00% 2.043MiB / 3.608GiB 0.06% 3.07kB / 2.86kB 4.1kB / 4.1kB 3
3614902a9596 distracted_wing 0.00% 2.391MiB / 3.608GiB 0.06% 794B / 0B 393kB / 8.19kB 3# 查看服务器内存资源,内存上限为 3694 / 1024 = 3.6074GB,证明docker容器的内存上限即为宿主机的内存上限
[root@VM-20-6-centos ~]# free -mtotal used free shared buff/cache available
Mem: 3694 1480 182 15 2030 1920
Swap: 0 0 0
–link container_name : alias 指定链接容器
# 新建一个容器
[root@VM-20-6-centos ~]# docker run -it --name mycentos1 centos:7 bash# 新建一个终端,再次新建一个容器,链接 mycentos1
[root@VM-20-6-centos ~]# docker run -it --name mycentos2 --link mycentos1:mywebsite1 centos:7 bash# 我们可以链接到mycentos1
[root@f4e2ec33ab52 /]# ping mycentos1
PING mywebsite1 (172.17.0.9) 56(84) bytes of data.
64 bytes from mywebsite1 (172.17.0.9): icmp_seq=1 ttl=64 time=0.144 ms[root@f4e2ec33ab52 /]# ping mywebsite1
PING mywebsite1 (172.17.0.9) 56(84) bytes of data.
64 bytes from mywebsite1 (172.17.0.9): icmp_seq=1 ttl=64 time=0.077 ms# 链接的本质, 对IP地址进行了DNS解析
[root@f4e2ec33ab52 /]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.9 mywebsite1 7da26a3a8ec3 mycentos1 # 重点在这
172.17.0.10 f4e2ec33ab52
Create My Degistry
目标:在Docker Hub上创建自己的私有仓库,因为仓库在海外,Nginx服务器占用空间较大,不便于传输这里使用较小镜像Busybox进行演示
BusyBox
BusyBox是一个集成了三百多个最常用的Linux命令和工具的软件,他集成压缩了Linux很多工具和命令,也包含了Linux系统自带的shell,http服务器和一个telnet服务器。实现这些所有功能仅占用1M左右的空间
CentOS原生安装busybox
# 使用wget安装busybox
[root@VM-20-6-centos ~]# wget https://busybox.net/downloads/binaries/1.28.1-defconfig-multiarch/busybox-x86_64 --no-check-certificate[root@VM-20-6-centos ~]# mv busybox-x86_64 busybox
# 赋予busybox可执行权限
[root@VM-20-6-centos ~]# chmod +x busybox
# 使用busybox
[root@VM-20-6-centos ~]# ./busybox ls /
Docker 镜像拉取busybox,并存储置Docker hub仓库中
1、 通过官网,选取适合的busybox版本
## 拉取镜像
[root@VM-20-6-centos ~]# docker pull busybox:1.36
1.36: Pulling from library/busybox
325d69979d33: Pull complete
Digest: sha256:560af6915bfc8d7630e50e212e08242d37b63bd5c1ccf9bd4acccf116e262d5b
Status: Downloaded newer image for busybox:1.36
docker.io/library/busybox:1.36
2、创建仓库
3、根据帮助命令修改镜像名称,推送置仓库
# 登录
[root@VM-20-6-centos ~]# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded# 按照帮助命令修改镜像名称
[root@VM-20-6-centos ~]# docker tag busybox:1.36 chinamaxxin/mybusybox:v1.36
# 查看镜像
[root@VM-20-6-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.24.0 1e96add5ea29 4 days ago 142MB
chinamaxxin/mynginx v1.23.4 a7be6198544f 4 days ago 142MB
nginx 1.23.4 a7be6198544f 4 days ago 142MB
chinamaxxin/mybusybox v1.36 8135583d97fe 8 days ago 4.86MB # 这两个
busybox 1.36 8135583d97fe 8 days ago 4.86MB
centos 7 eeb6ee3f44bd 20 months ago 204MB
nginx 1.18.0-alpine 684dbf9f01f3 2 years ago 21.9MB# 推送镜像到仓库
[root@VM-20-6-centos ~]# docker push chinamaxxin/mybusybox:v1.36
The push refers to repository [docker.io/chinamaxxin/mybusybox]
9547b4c33213: Mounted from library/busybox
v1.36: digest: sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43 size: 528# 我们还可以不加版本号 docker push chinamaxxin/mybusybox -a 就将所有chinamaxxin/mybusybox 所有版本的镜像都push上去了
腾讯云镜像仓库搭建
先创建命名空间,再创建镜像仓库
# 快捷指令
# 登录腾讯云容器镜像服务 Docker Registry
docker login ccr.ccs.tencentyun.com --username=100025947277
# 从 Registry 拉取镜像
docker pull ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:[tag]
# 向 Registry 中推送镜像
docker tag [imageId] ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:[tag]
docker push ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:[tag]
# 使用快捷指令登录
[root@VM-20-6-centos ~]# docker login ccr.ccs.tencentyun.com --username=100025947277
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
# 使用repository:tag 更改镜像名称
[root@VM-20-6-centos ~]# docker tag busybox:1.36 ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:v1.36
# 使用 Image ID 更改镜像名称
[root@VM-20-6-centos ~]# docker tag 8135583d97fe ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:vv1.36[root@VM-20-6-centos ~]# docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1 v1.36 8135583d97fe 8 days ago 4.86MB
ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1 vv1.36 8135583d97fe 8 days ago 4.86MB# 将两个版本使用docker push -a全部推上去
[root@VM-20-6-centos ~]# docker push ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1 -a
The push refers to repository [ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1]
9547b4c33213: Pushed
v1.36: digest: sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43 size: 528
9547b4c33213: Layer already exists
vv1.36: digest: sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43 size: 528# 可以看到镜像已经推送成功啦
# 从私有仓库中拉去镜像
[root@VM-20-6-centos ~]# docker pull ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:v1.36
v1.36: Pulling from maxxin1/busyboxbymaxxin1
Digest: sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43
Status: Image is up to date for ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:v1.36
ccr.ccs.tencentyun.com/maxxin1/busyboxbymaxxin1:v1.36# 退出仓库
[root@VM-20-6-centos ~]# docker logout ccr.ccs.tencentyun.com
Removing login credentials for ccr.ccs.tencentyun.com