容器镜像构建及推送阿里云容器镜像服务测试

简介: 容器镜像构建及推送阿里云容器镜像服务测试

1.创建Docker file

/etc/docker/dockerfile/目录下新建一个Docerfile

vi /etc/docker/dockerfile/Dockerfile

Dockerfile的内容如下:

FROM centos
MAINTAINER Xiaobo<xxxxx@qq.com>
RUN yum install nginx
COPY testfile.html /usr/share/nginx/html/
ENV TZ=Asia/Shanghai
EXPOSE 80CMD ["nginx","-g","daemon off;"]

Dockerfile的内容解析

  • FROM centos #指定镜像继承自centos的docker镜像
  • MAINTAINER Xiaobo<947089528@qq.com> #镜像的维护者和邮箱
  • RUN yum install nginx #执行RUN后面的命令,执行时间是在docker build的时候,有两种格式


shell 格式:

RUN <命令行命令># <命令行命令> 等同于,在终端操作的 shell 命令。


exec 格式:

RUN ["可执行文件","参数1","参数2"]# 例如:# RUN ["./test.php", "dev", "offline"] 等价于 RUN ./test.php dev offline

  • COPY testfile.html /usr/share/nginx/html/ #把testfile拷贝到容器中的/usr/share/nginx/html/目录下,不存在会自动创建。
  • ENV TZ=Asia/Shanghai #设置环境变量,设置timezone为Asia/Shanghai
  • EXPOSE 80 #声明端口
  • CMD ["nginx","-g","daemon off;"] #运行程序,CMD是在docker run时运行。


Docker 容器启动时,默认会把容器内部第一个进程,也就是pid=1的程序,作为docker容器是否正在运行的依据,如果 docker 容器pid=1的进程挂了,那么docker容器便会直接退出。

nginx默认是以后台模式启动的,Docker未执行自定义的CMD之前,nginx的pid是1,执行到CMD之后,nginx就在后台运行,bash或sh脚本的pid变成了1。所以一旦执行完自定义CMD,nginx容器也就退出了。为了保持nginx的容器不退出,应该关闭nginx后台运行,所以用-g daemon off关闭后台运行。

原文:If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!


2.构建镜像

(1)使用docker build -t nginx:v1 .命令构建docker镜像

[root@iZm5e1wm3ud5qa2atm67ooZ dockerfile]# docker build -t nginx:v1 .Sending build context to Docker daemon  3.072kB
Step 1/7 : FROM centos
---> 300e315adb2f
Step 2/7 : MAINTAINER Xiaobo<xxxxxx@qq.com>
---> Using cache
---> 97b62ee6ef6f
Step 3/7 : RUN yum install nginx -y---> Running in 8af7ee643936
CentOS Linux 8- AppStream                      7.8 MB/s | 6.3 MB     00:00    
CentOS Linux 8- BaseOS                         3.4 MB/s | 2.3 MB     00:00    
CentOS Linux 8- Extras                          19 kB/s | 9.6 kB     00:00    
Dependencies resolved.
============================================================================================== Package                       Arch    Version                                Repo        Size
==============================================================================================Installing:
 nginx                         x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream  570 k
Upgrading:
 openssl-libs                  x86_64  1:1.1.1g-15.el8_3                      baseos     1.5 M
Installing dependencies:
 dejavu-fonts-common           noarch  2.35-6.el8                             baseos      74 k
 dejavu-sans-fonts             noarch  2.35-6.el8                             baseos     1.5 M
 fontconfig                    x86_64  2.13.1-3.el8                           baseos     275 k
 fontpackages-filesystem       noarch  1.44-22.el8                            baseos      16 k
 freetype                      x86_64  2.9.1-4.el8_3.1                        baseos     394 k
 gd                            x86_64  2.2.5-7.el8                            appstream  144 k
 jbigkit-libs                  x86_64  2.1-14.el8                             appstream   55 k
 libX11                        x86_64  1.6.8-3.el8                            appstream  611 k
 libX11-common                 noarch  1.6.8-3.el8                            appstream  158 k
 libXau                        x86_64  1.0.9-3.el8                            appstream   37 k
 libXpm                        x86_64  3.5.12-8.el8                           appstream   58 k
 libjpeg-turbo                 x86_64  1.5.3-10.el8                           appstream  156 k
 libpng                        x86_64  2:1.6.34-5.el8                         baseos     126 k
 libtiff                       x86_64  4.0.9-18.el8                           appstream  188 k
 libwebp                       x86_64  1.0.0-1.el8                            appstream  273 k
 libxcb                        x86_64  1.13.1-1.el8                           appstream  229 k
 libxslt                       x86_64  1.1.32-5.el8                           baseos     250 k
 nginx-all-modules             noarch  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   23 k
 nginx-filesystem              noarch  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   24 k
 nginx-mod-http-image-filter   x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   35 k
 nginx-mod-http-perl           x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   45 k
 nginx-mod-http-xslt-filter    x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   33 k
 nginx-mod-mail                x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   64 k
 nginx-mod-stream              x86_64  1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream   85 k
openssl                       x86_64  1:1.1.1g-15.el8_3                      baseos     707 k
 perl-Carp                     noarch  1.42-396.el8                           baseos      30 k
 perl-Errno                    x86_64  1.28-416.el8                           baseos      76 k
 perl-Exporter                 noarch  5.72-396.el8                           baseos      34 k
 perl-File-Path                noarch  2.15-2.el8                             baseos      38 k
 perl-IO                       x86_64  1.38-416.el8                           baseos     141 k
 perl-PathTools                x86_64  3.74-1.el8                             baseos      90 k
 perl-Scalar-List-Utils        x86_64  3:1.49-2.el8                           baseos      68 k
 perl-Socket                   x86_64  4:2.027-3.el8                          baseos      59 k
 perl-Text-Tabs+Wrap           noarch  2013.0523-395.el8                      baseos      24 k
 perl-Unicode-Normalize        x86_64  1.25-396.el8                           baseos      82 k
 perl-constant                 noarch  1.33-396.el8                           baseos      25 k
 perl-interpreter              x86_64  4:5.26.3-416.el8                       baseos     6.3 M
 perl-libs                     x86_64  4:5.26.3-416.el8                       baseos     1.6 M
 perl-macros                   x86_64  4:5.26.3-416.el8                       baseos      72 k
 perl-parent                   noarch  1:0.237-1.el8                          baseos      20 k
 perl-threads                  x86_64  1:2.21-2.el8                           baseos      61 k
 perl-threads-shared           x86_64  1.58-2.el8                             baseos      48 k
Installing weak dependencies:
 openssl-pkcs11                x86_64  0.4.10-2.el8                           baseos      66 k
Enabling module streams:
 nginx                                 1.14                                                   
Transaction Summary
==============================================================================================Install  44 Packages
Upgrade   1 Package
Total download size: 16 M
Downloading Packages:
(1/45): gd-2.2.5-7.el8.x86_64.rpm               1.6 MB/s | 144 kB     00:00    
(2/45): jbigkit-libs-2.1-14.el8.x86_64.rpm      566 kB/s |  55 kB     00:00    
(3/45): libX11-common-1.6.8-3.el8.noarch.rpm    4.7 MB/s | 158 kB     00:00    
(4/45): libX11-1.6.8-3.el8.x86_64.rpm           4.8 MB/s | 611 kB     00:00    
(5/45): libXau-1.0.9-3.el8.x86_64.rpm           867 kB/s |  37 kB     00:00    
(6/45): libXpm-3.5.12-8.el8.x86_64.rpm          1.4 MB/s |  58 kB     00:00    
(7/45): libjpeg-turbo-1.5.3-10.el8.x86_64.rpm   2.5 MB/s | 156 kB     00:00    
(8/45): libtiff-4.0.9-18.el8.x86_64.rpm         1.8 MB/s | 188 kB     00:00    
(9/45): libwebp-1.0.0-1.el8.x86_64.rpm          3.1 MB/s | 273 kB     00:00    
(10/45): libxcb-1.13.1-1.el8.x86_64.rpm         2.9 MB/s | 229 kB     00:00    
(11/45): nginx-all-modules-1.14.1-9.module_el8. 408 kB/s |  23 kB     00:00    
(12/45): nginx-1.14.1-9.module_el8.0.0+184+e34f 7.7 MB/s | 570 kB     00:00    
(13/45): nginx-filesystem-1.14.1-9.module_el8.0 310 kB/s |  24 kB     00:00    
(14/45): nginx-mod-http-image-filter-1.14.1-9.m 663 kB/s |  35 kB     00:00    
(15/45): nginx-mod-http-perl-1.14.1-9.module_el 645 kB/s |  45 kB     00:00    
(16/45): nginx-mod-http-xslt-filter-1.14.1-9.mo 531 kB/s |  33 kB     00:00    
(17/45): nginx-mod-mail-1.14.1-9.module_el8.0.0 895 kB/s |  64 kB     00:00    
(18/45): nginx-mod-stream-1.14.1-9.module_el8.0 1.1 MB/s |  85 kB     00:00    
(19/45): dejavu-fonts-common-2.35-6.el8.noarch. 951 kB/s |  74 kB     00:00    
(20/45): fontconfig-2.13.1-3.el8.x86_64.rpm     3.1 MB/s | 275 kB     00:00    
(21/45): dejavu-sans-fonts-2.35-6.el8.noarch.rp  12 MB/s | 1.5 MB     00:00    
(22/45): fontpackages-filesystem-1.44-22.el8.no 205 kB/s |  16 kB     00:00    
(23/45): freetype-2.9.1-4.el8_3.1.x86_64.rpm    8.0 MB/s | 394 kB     00:00    
(24/45): libpng-1.6.34-5.el8.x86_64.rpm         2.5 MB/s | 126 kB     00:00    
(25/45): libxslt-1.1.32-5.el8.x86_64.rpm        3.2 MB/s | 250 kB     00:00    
(26/45): openssl-1.1.1g-15.el8_3.x86_64.rpm     8.4 MB/s | 707 kB     00:00    
(27/45): openssl-pkcs11-0.4.10-2.el8.x86_64.rpm 879 kB/s |  66 kB     00:00    
(28/45): perl-Carp-1.42-396.el8.noarch.rpm      391 kB/s |  30 kB     00:00    
(29/45): perl-Errno-1.28-416.el8.x86_64.rpm     1.2 MB/s |  76 kB     00:00    
(30/45): perl-Exporter-5.72-396.el8.noarch.rpm  474 kB/s |  34 kB     00:00    
(31/45): perl-File-Path-2.15-2.el8.noarch.rpm   564 kB/s |  38 kB     00:00    
(32/45): perl-IO-1.38-416.el8.x86_64.rpm        1.8 MB/s | 141 kB     00:00    
(33/45): perl-PathTools-3.74-1.el8.x86_64.rpm   1.1 MB/s |  90 kB     00:00    
(34/45): perl-Scalar-List-Utils-1.49-2.el8.x86_ 899 kB/s |  68 kB     00:00    
(35/45): perl-Socket-2.027-3.el8.x86_64.rpm     816 kB/s |  59 kB     00:00    
(36/45): perl-Text-Tabs+Wrap-2013.0523-395.el8. 250 kB/s |  24 kB     00:00    
(37/45): perl-Unicode-Normalize-1.25-396.el8.x8 1.1 MB/s |  82 kB     00:00    
(38/45): perl-constant-1.33-396.el8.noarch.rpm  350 kB/s |  25 kB     00:00    
(39/45): perl-macros-5.26.3-416.el8.x86_64.rpm  878 kB/s |  72 kB     00:00    
(40/45): perl-parent-0.237-1.el8.noarch.rpm     965 kB/s |  20 kB     00:00    
(41/45): perl-threads-2.21-2.el8.x86_64.rpm     2.2 MB/s |  61 kB     00:00    
(42/45): perl-libs-5.26.3-416.el8.x86_64.rpm    9.4 MB/s | 1.6 MB     00:00    
(43/45): perl-threads-shared-1.58-2.el8.x86_64. 2.2 MB/s |  48 kB     00:00    
(44/45): perl-interpreter-5.26.3-416.el8.x86_64  24 MB/s | 6.3 MB     00:00    
(45/45): openssl-libs-1.1.1g-15.el8_3.x86_64.rp 9.0 MB/s | 1.5 MB     00:00    
--------------------------------------------------------------------------------Total                                           7.5 MB/s |  16 MB     00:02     
warning: /var/cache/dnf/appstream-02e86d1c976ab532/packages/gd-2.2.5-7.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS Linux 8- AppStream                      1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>" Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : perl-Exporter-5.72-396.el8.noarch                     1/46 
  Installing       : perl-libs-4:5.26.3-416.el8.x86_64                     2/46 
  Installing       : perl-Carp-1.42-396.el8.noarch                         3/46 
  Installing       : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64            4/46 
  Upgrading        : openssl-libs-1:1.1.1g-15.el8_3.x86_64                 5/46 
  Running scriptlet: openssl-libs-1:1.1.1g-15.el8_3.x86_64                 5/46 
  Installing       : openssl-1:1.1.1g-15.el8_3.x86_64                      6/46 
  Installing       : openssl-pkcs11-0.4.10-2.el8.x86_64                    7/46 
  Installing       : libpng-2:1.6.34-5.el8.x86_64                          8/46 
  Installing       : freetype-2.9.1-4.el8_3.1.x86_64                       9/46 
  Installing       : fontpackages-filesystem-1.44-22.el8.noarch           10/46 
  Installing       : libjpeg-turbo-1.5.3-10.el8.x86_64                    11/46 
  Installing       : dejavu-fonts-common-2.35-6.el8.noarch                12/46 
  Installing       : dejavu-sans-fonts-2.35-6.el8.noarch                  13/46 
  Installing       : fontconfig-2.13.1-3.el8.x86_64                       14/46 
  Running scriptlet: fontconfig-2.13.1-3.el8.x86_64                       14/46 
  Installing       : perl-macros-4:5.26.3-416.el8.x86_64                  15/46 
  Installing       : perl-parent-1:0.237-1.el8.noarch                     16/46 
  Installing       : perl-Errno-1.28-416.el8.x86_64                       17/46 
  Installing       : perl-Socket-4:2.027-3.el8.x86_64                     18/46 
  Installing       : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch         19/46 
  Installing       : perl-Unicode-Normalize-1.25-396.el8.x86_64           20/46 
  Installing       : perl-File-Path-2.15-2.el8.noarch                     21/46 
  Installing       : perl-IO-1.38-416.el8.x86_64                          22/46 
  Installing       : perl-PathTools-3.74-1.el8.x86_64                     23/46 
  Installing       : perl-constant-1.33-396.el8.noarch                    24/46 
  Installing       : perl-threads-1:2.21-2.el8.x86_64                     25/46 
  Installing       : perl-threads-shared-1.58-2.el8.x86_64                26/46 
  Installing       : perl-interpreter-4:5.26.3-416.el8.x86_64             27/46 
  Installing       : libxslt-1.1.32-5.el8.x86_64                          28/46 
  Running scriptlet: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34   29/46 
  Installing       : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34   29/46 
  Installing       : libwebp-1.0.0-1.el8.x86_64                           30/46 
  Installing       : libXau-1.0.9-3.el8.x86_64                            31/46 
  Installing       : libxcb-1.13.1-1.el8.x86_64                           32/46 
  Installing       : libX11-common-1.6.8-3.el8.noarch                     33/46 
  Installing       : libX11-1.6.8-3.el8.x86_64                            34/46 
  Installing       : libXpm-3.5.12-8.el8.x86_64                           35/46 
  Installing       : jbigkit-libs-2.1-14.el8.x86_64                       36/46 
  Running scriptlet: jbigkit-libs-2.1-14.el8.x86_64                       36/46 
  Installing       : libtiff-4.0.9-18.el8.x86_64                          37/46 
  Installing       : gd-2.2.5-7.el8.x86_64                                38/46 
  Running scriptlet: gd-2.2.5-7.el8.x86_64                                38/46 
  Installing       : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+39/46 
  Running scriptlet: nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+39/46 
  Installing       : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0   40/46 
  Running scriptlet: nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0   40/46 
  Installing       : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe   41/46 
  Running scriptlet: nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe   41/46 
  Installing       : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34   42/46 
  Running scriptlet: nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34   42/46 
  Installing       : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6   43/46 
  Running scriptlet: nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6   43/46 
  Installing       : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.   44/46 
  Running scriptlet: nginx-mod-http-image-filter-1:1.14.1-9.module_el8.   44/46 
  Installing       : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e3   45/46 
  Cleanup          : openssl-libs-1:1.1.1g-11.el8.x86_64                  46/46 
  Running scriptlet: openssl-libs-1:1.1.1g-11.el8.x86_64                  46/46 
  Running scriptlet: fontconfig-2.13.1-3.el8.x86_64                       46/46 
  Verifying        : gd-2.2.5-7.el8.x86_64                                 1/46 
  Verifying        : jbigkit-libs-2.1-14.el8.x86_64                        2/46 
  Verifying        : libX11-1.6.8-3.el8.x86_64                             3/46 
  Verifying        : libX11-common-1.6.8-3.el8.noarch                      4/46 
  Verifying        : libXau-1.0.9-3.el8.x86_64                             5/46 
  Verifying        : libXpm-3.5.12-8.el8.x86_64                            6/46 
  Verifying        : libjpeg-turbo-1.5.3-10.el8.x86_64                     7/46 
  Verifying        : libtiff-4.0.9-18.el8.x86_64                           8/46 
  Verifying        : libwebp-1.0.0-1.el8.x86_64                            9/46 
  Verifying        : libxcb-1.13.1-1.el8.x86_64                           10/46 
  Verifying        : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6   11/46 
  Verifying        : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e3   12/46 
  Verifying        : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34   13/46 
  Verifying        : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.   14/46 
  Verifying        : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+15/46 
  Verifying        : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0   16/46 
  Verifying        : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe   17/46 
  Verifying        : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34   18/46 
  Verifying        : dejavu-fonts-common-2.35-6.el8.noarch                19/46 
  Verifying        : dejavu-sans-fonts-2.35-6.el8.noarch                  20/46 
  Verifying        : fontconfig-2.13.1-3.el8.x86_64                       21/46 
  Verifying        : fontpackages-filesystem-1.44-22.el8.noarch           22/46 
  Verifying        : freetype-2.9.1-4.el8_3.1.x86_64                      23/46 
  Verifying        : libpng-2:1.6.34-5.el8.x86_64                         24/46 
  Verifying        : libxslt-1.1.32-5.el8.x86_64                          25/46 
  Verifying        : openssl-1:1.1.1g-15.el8_3.x86_64                     26/46 
  Verifying        : openssl-pkcs11-0.4.10-2.el8.x86_64                   27/46 
  Verifying        : perl-Carp-1.42-396.el8.noarch                        28/46 
  Verifying        : perl-Errno-1.28-416.el8.x86_64                       29/46 
  Verifying        : perl-Exporter-5.72-396.el8.noarch                    30/46 
  Verifying        : perl-File-Path-2.15-2.el8.noarch                     31/46 
  Verifying        : perl-IO-1.38-416.el8.x86_64                          32/46 
  Verifying        : perl-PathTools-3.74-1.el8.x86_64                     33/46 
  Verifying        : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64           34/46 
  Verifying        : perl-Socket-4:2.027-3.el8.x86_64                     35/46 
  Verifying        : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch         36/46 
  Verifying        : perl-Unicode-Normalize-1.25-396.el8.x86_64           37/46 
  Verifying        : perl-constant-1.33-396.el8.noarch                    38/46 
  Verifying        : perl-interpreter-4:5.26.3-416.el8.x86_64             39/46 
  Verifying        : perl-libs-4:5.26.3-416.el8.x86_64                    40/46 
  Verifying        : perl-macros-4:5.26.3-416.el8.x86_64                  41/46 
  Verifying        : perl-parent-1:0.237-1.el8.noarch                     42/46 
  Verifying        : perl-threads-1:2.21-2.el8.x86_64                     43/46 
  Verifying        : perl-threads-shared-1.58-2.el8.x86_64                44/46 
  Verifying        : openssl-libs-1:1.1.1g-15.el8_3.x86_64                45/46 
  Verifying        : openssl-libs-1:1.1.1g-11.el8.x86_64                  46/46 
Upgraded:
  openssl-libs-1:1.1.1g-15.el8_3.x86_64                                         
Installed:
  dejavu-fonts-common-2.35-6.el8.noarch                                         
  dejavu-sans-fonts-2.35-6.el8.noarch                                           
  fontconfig-2.13.1-3.el8.x86_64                                                
  fontpackages-filesystem-1.44-22.el8.noarch                                    
  freetype-2.9.1-4.el8_3.1.x86_64                                               
  gd-2.2.5-7.el8.x86_64                                                         
  jbigkit-libs-2.1-14.el8.x86_64                                                
  libX11-1.6.8-3.el8.x86_64                                                     
  libX11-common-1.6.8-3.el8.noarch                                              
  libXau-1.0.9-3.el8.x86_64                                                     
  libXpm-3.5.12-8.el8.x86_64                                                    
  libjpeg-turbo-1.5.3-10.el8.x86_64                                             
  libpng-2:1.6.34-5.el8.x86_64                                                  
  libtiff-4.0.9-18.el8.x86_64                                                   
  libwebp-1.0.0-1.el8.x86_64                                                    
  libxcb-1.13.1-1.el8.x86_64                                                    
  libxslt-1.1.32-5.el8.x86_64                                                   
  nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64                           
  nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch               
  nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch                
  nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64     
  nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64             
  nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64      
  nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64                  
  nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64                
  openssl-1:1.1.1g-15.el8_3.x86_64                                              
  openssl-pkcs11-0.4.10-2.el8.x86_64                                            
  perl-Carp-1.42-396.el8.noarch                                                 
  perl-Errno-1.28-416.el8.x86_64                                                
  perl-Exporter-5.72-396.el8.noarch                                             
  perl-File-Path-2.15-2.el8.noarch                                              
  perl-IO-1.38-416.el8.x86_64                                                   
  perl-PathTools-3.74-1.el8.x86_64                                              
  perl-Scalar-List-Utils-3:1.49-2.el8.x86_64                                    
  perl-Socket-4:2.027-3.el8.x86_64                                              
  perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch                                  
  perl-Unicode-Normalize-1.25-396.el8.x86_64                                    
  perl-constant-1.33-396.el8.noarch                                             
  perl-interpreter-4:5.26.3-416.el8.x86_64                                      
  perl-libs-4:5.26.3-416.el8.x86_64                                             
  perl-macros-4:5.26.3-416.el8.x86_64                                           
  perl-parent-1:0.237-1.el8.noarch                                              
  perl-threads-1:2.21-2.el8.x86_64                                              
  perl-threads-shared-1.58-2.el8.x86_64                                         
Complete!
Removing intermediate container 8af7ee643936
---> b65c9c7f6c65
Step 4/7 : COPY testfile.html /usr/share/nginx/html/
---> 669f455c55d9
Step 5/7 : ENV TZ=Asia/Shanghai
---> Running in 8ccc4db83d35
Removing intermediate container 8ccc4db83d35
---> f7ef58c74a94
Step 6/7 : EXPOSE 80---> Running in d66bbfb1a8d8
Removing intermediate container d66bbfb1a8d8
---> 4527e71ef4c0
Step 7/7 : CMD ["nginx","-g","daemon off;"]
---> Running in 2c634ef1b0f6
Removing intermediate container 2c634ef1b0f6
---> 63e9675f385f
Successfully built 63e9675f385f
Successfully tagged nginx:v1
[root@iZm5e1wm3ud5qa2atm67ooZ dockerfile]#

可以用docker images查看本地主机上的镜像


3.使用创建的docker镜像启动容器并测试访问容器

(1)使用如下命令指定创建的镜像启动容器

docker run -itd--name=nginx -p80:80 nginx:v1


(2)检查内核转发是否已经开启,如果没有开启echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf,然后sysctl -p


(3)检查iptables的FORWARD链是否默认DROP,如果是默认DROP,则iptables -P FORWARD ACCEPT设为默认ACCEPT


(4)测试访问docker应用



4.推送自建镜像到阿里云容器镜像服务


(1)首先创建好阿里云容器镜像服务ACR的仓库。


(2)本地登录容器镜像仓库

docker login --username=user@domain registry.cn-qingdao.aliyuncs.com


(3)推送本地创建镜像到镜像仓库

docker tag [ImageId] registry.cn-qingdao.aliyuncs.com/xiaobo-test/docker-test:[镜像版本号]
docker push registry.cn-qingdao.aliyuncs.com/xiaobo-test/docker-test:[镜像版本号]


(4)阿里云控制台可以看到推送的镜像了。

相关实践学习
通过ACR快速部署网站应用
本次实验任务是在云上基于ECS部署Docker环境,制作网站镜像并上传至ACR镜像仓库,通过容器镜像运行网站应用,网站运行在Docker容器中、网站业务数据存储在Mariadb数据库中、网站文件数据存储在服务器ECS云盘中,通过公网地址进行访问。
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
3月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
576 7
|
4月前
|
存储 Kubernetes 网络安全
关于阿里云 Kubernetes 容器服务(ACK)添加镜像仓库的快速说明
本文介绍了在中国大陆地区因网络限制无法正常拉取 Docker 镜像的解决方案。作者所在的阿里云 Kubernetes 集群使用的是较旧版本的 containerd(1.2x),且无法直接通过 SSH 修改节点配置,因此采用了一种无需更改 Kubernetes 配置文件的方法。通过为 `docker.io` 添加 containerd 的镜像源,并使用脚本自动修改 containerd 配置文件中的路径错误(将错误的 `cert.d` 改为 `certs.d`),最终实现了通过多个镜像站点拉取镜像。作者还提供了一个可重复运行的脚本,用于动态配置镜像源。虽然该方案能缓解镜像拉取问题,
517 2
|
5月前
|
缓存 Ubuntu Docker
Ubuntu环境下删除Docker镜像与容器、配置静态IP地址教程。
如果遇见问题或者想回滚改动, 可以重启系统.
374 16
|
5月前
|
Ubuntu 网络安全 PHP
如何使用vscode的Docker插件管理ubuntu 拉取服务器的镜像以及创建容器
本测试镜像旨在记录使用vscode的Docker插件拉取病创建Dockerfile,以及拉取镜像。
|
8月前
|
关系型数据库 MySQL Docker
|
10月前
|
关系型数据库 测试技术 分布式数据库
刷新世界纪录!阿里云PolarDB凭借创新的「三层解耦」架构刷新TPC-C基准测试世界纪录
刷新世界纪录!阿里云PolarDB凭借创新的「三层解耦」架构刷新TPC-C基准测试世界纪录
|
10月前
|
安全 持续交付 云计算
课时5:阿里云容器服务:最原生的集成Docker和云服务
阿里云容器服务以服务化形式构建容器基础设施,大幅提升开发效率,简化应用部署流程。通过Docker容器和DevOps工具(如Jenkins),实现自动化部署与迭代,优化企业内部复杂部署问题。该服务支持GPU调度、混合云架构无缝迁移,并与阿里云产品体系无缝集成,提供安全防护、网络负载均衡等多重功能支持。凭借微服务架构,帮助企业突破业务瓶颈,提高资源利用率,轻松应对海量流量。
366 0
课时5:阿里云容器服务:最原生的集成Docker和云服务
|
10月前
|
人工智能 Kubernetes Serverless
阿里云向全球客户推出创新容器计算服务ACS,可降低算力成本高达55%
阿里云向全球客户推出创新容器计算服务ACS,可降低算力成本高达55%
|
11月前
|
弹性计算 监控 持续交付
面对热点事件,阿里云如何通过云上弹性与容器服务帮助客户应对流量洪峰
面对热点事件,阿里云如何通过云上弹性与容器服务帮助客户应对流量洪峰
274 0
|
11月前
|
监控 Cloud Native Java
基于阿里云容器服务(ACK)的微服务架构设计与实践
本文介绍如何利用阿里云容器服务Kubernetes版(ACK)构建高可用、可扩展的微服务架构。通过电商平台案例,展示基于Java(Spring Boot)、Docker、Nacos等技术的开发、容器化、部署流程,涵盖服务注册、API网关、监控日志及性能优化实践,帮助企业实现云原生转型。

相关产品

  • 容器镜像服务