Docker镜像制作和管理

Posted Janzen_Q

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker镜像制作和管理相关的知识,希望对你有一定的参考价值。

一、Docker镜像说明

二、基于容器通过 docker commit 手动制作镜像

1、基于容器手动制作镜像步骤

1、下载官方系统镜像

2、基于官方基础镜像启动容器,并进入容器

3、在容器中进行配置操作

  3.1、安装基础工具

  3.2、配置运行环境

  3.3、安装并配置服务

  3.4、存放业务程序代码

4、docker commit 提交生成新镜像

5、基于定制镜像生成容器并测试

2、基于centos7官方镜像,手动制作yum安装nginx定制镜像

2.1、下载centos7官方镜像,并启动进入容器

centos官方镜像:https://hub.docker.com/_/centos/tags

[root@Docker-Ubu1804-p11:~]# docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete 
Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[root@Docker-Ubu1804-p11:~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              c059bfaa849c        17 months ago       5.59MB
hello-world         latest              feb5d9fea6a5        19 months ago       13.3kB
centos              7                   eeb6ee3f44bd        19 months ago       204MB
[root@Docker-Ubu1804-p11:~]# docker run -d --name centos-nginx centos:7 tail -f /etc/hosts
502a7a7faae8b7a3c3fa177baec1009d1bc9caabb8b782f887767b35e16ecb8a
[root@Docker-Ubu1804-p11:~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
502a7a7faae8        centos:7            "tail -f /etc/hosts"   8 seconds ago       Up 7 seconds                            centos-nginx
[root@Docker-Ubu1804-p11:~]# docker exec -it centos-nginx bash
[root@502a7a7faae8 /]# 

 

2.2、在容器内安装基础工具,并配置环境

 

##配置容器内 yum
[root@502a7a7faae8 /]# rm -rf /etc/yum.repos.d/*
[root@502a7a7faae8 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  28084      0 --:--:-- --:--:-- --:--:-- 28348
[root@502a7a7faae8 /]# ls /etc/yum.repos.d/
CentOS-Base.repo
[root@502a7a7faae8 /]# yum clean all
Loaded plugins: fastestmirror, ovl
Cleaning repos: base extras updates
[root@502a7a7faae8 /]# yum makecache fast
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                     | 3.6 kB  00:00:00     
extras                                                                                                                   | 2.9 kB  00:00:00     
updates                                                                                                                  | 2.9 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                            | 153 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                        | 249 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                                                                       |  20 MB  00:00:08     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
(4/4): base/7/x86_64/primary_db                                                                                          | 6.1 MB  00:00:01     
Metadata Cache Created


##yum安装常用基础工具
[root@502a7a7faae8 /]# yum install -y psmisc tree wget vim net-tools bash-completion
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package bash-completion.noarch 1:2.1-8.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
---> Package psmisc.x86_64 0:22.20-17.el7 will be installed
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be installed
--> Processing Dependency: vim-common = 2:7.4.629-8.el7_9 for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: which for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.7-6.el7 will be installed
---> Package perl.x86_64 4:5.16.3-299.el7_9 will be installed
--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-299.el7_9.x86_64
---> Package perl-libs.x86_64 4:5.16.3-299.el7_9 will be installed
---> Package vim-common.x86_64 2:7.4.629-8.el7_9 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-8.el7_9.x86_64
---> Package which.x86_64 0:2.20-7.el7 will be installed
--> Running transaction check
---> Package perl-Carp.noarch 0:1.26-244.el7 will be installed
---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch
---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
--> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
---> Package perl-Socket.x86_64 0:2.010-5.el7 will be installed
---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
---> Package perl-constant.noarch 0:1.27-2.el7 will be installed
---> Package perl-macros.x86_64 4:5.16.3-299.el7_9 will be installed
---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
---> Package vim-filesystem.x86_64 2:7.4.629-8.el7_9 will be installed
--> Running transaction check
---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
---> Package perl-Pod-Escapes.noarch 1:1.04-299.el7_9 will be installed
---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
--> Running transaction check
---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
---> Package perl-parent.noarch 1:0.225-244.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================
 Package                                  Arch                     Version                                      Repository                 Size
================================================================================================================================================
Installing:
 bash-completion                          noarch                   1:2.1-8.el7                                  base                       87 k
 net-tools                                x86_64                   2.0-0.25.20131004git.el7                     base                      306 k
 psmisc                                   x86_64                   22.20-17.el7                                 base                      141 k
 tree                                     x86_64                   1.6.0-10.el7                                 base                       46 k
 vim-enhanced                             x86_64                   2:7.4.629-8.el7_9                            updates                   1.1 M
 wget                                     x86_64                   1.14-18.el7_6.1                              base                      547 k
Installing for dependencies:
 gpm-libs                                 x86_64                   1.20.7-6.el7                                 base                       32 k
 groff-base                               x86_64                   1.22.2-8.el7                                 base                      942 k
 perl                                     x86_64                   4:5.16.3-299.el7_9                           updates                   8.0 M
 perl-Carp                                noarch                   1.26-244.el7                                 base                       19 k
 perl-Encode                              x86_64                   2.51-7.el7                                   base                      1.5 M
 perl-Exporter                            noarch                   5.68-3.el7                                   base                       28 k
 perl-File-Path                           noarch                   2.09-2.el7                                   base                       26 k
 perl-File-Temp                           noarch                   0.23.01-3.el7                                base                       56 k
 perl-Filter                              x86_64                   1.49-3.el7                                   base                       76 k
 perl-Getopt-Long                         noarch                   2.40-3.el7                                   base                       56 k
 perl-HTTP-Tiny                           noarch                   0.033-3.el7                                  base                       38 k
 perl-PathTools                           x86_64                   3.40-5.el7                                   base                       82 k
 perl-Pod-Escapes                         noarch                   1:1.04-299.el7_9                             updates                    52 k
 perl-Pod-Perldoc                         noarch                   3.20-4.el7                                   base                       87 k
 perl-Pod-Simple                          noarch                   1:3.28-4.el7                                 base                      216 k
 perl-Pod-Usage                           noarch                   1.63-3.el7                                   base                       27 k
 perl-Scalar-List-Utils                   x86_64                   1.27-248.el7                                 base                       36 k
 perl-Socket                              x86_64                   2.010-5.el7                                  base                       49 k
 perl-Storable                            x86_64                   2.45-3.el7                                   base                       77 k
 perl-Text-ParseWords                     noarch                   3.29-4.el7                                   base                       14 k
 perl-Time-HiRes                          x86_64                   4:1.9725-3.el7                               base                       45 k
 perl-Time-Local                          noarch                   1.2300-2.el7                                 base                       24 k
 perl-constant                            noarch                   1.27-2.el7                                   base                       19 k
 perl-libs                                x86_64                   4:5.16.3-299.el7_9                           updates                   690 k
 perl-macros                              x86_64                   4:5.16.3-299.el7_9                           updates                    44 k
 perl-parent                              noarch                   1:0.225-244.el7                              base                       12 k
 perl-podlators                           noarch                   2.5.1-3.el7                                  base                      112 k
 perl-threads                             x86_64                   1.87-4.el7                                   base                       49 k
 perl-threads-shared                      x86_64                   1.43-6.el7                                   base                       39 k
 vim-common                               x86_64                   2:7.4.629-8.el7_9                            updates                   5.9 M
 vim-filesystem                           x86_64                   2:7.4.629-8.el7_9                            updates                    11 k
 which                                    x86_64                   2.20-7.el7                                   base                       41 k

Transaction Summary
================================================================================================================================================
Install  6 Packages (+32 Dependent packages)

Total download size: 20 M
Installed size: 67 M
Downloading packages:
groff-base-1.22.2-8.el7.x86_64 FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/groff-base-1.22.2-8.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
warning: /var/cache/yum/x86_64/7/base/packages/gpm-libs-1.20.7-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY-:-- ETA 
Public key for gpm-libs-1.20.7-6.el7.x86_64.rpm is not installed
(1/38): gpm-libs-1.20.7-6.el7.x86_64.rpm                                                                                 |  32 kB  00:00:00     
(2/38): bash-completion-2.1-8.el7.noarch.rpm                                                                             |  87 kB  00:00:00     
(3/38): net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                                    | 306 kB  00:00:00     
(4/38): perl-Carp-1.26-244.el7.noarch.rpm                                                                                |  19 kB  00:00:00     
(5/38): perl-Exporter-5.68-3.el7.noarch.rpm                                                                              |  28 kB  00:00:00     
(6/38): perl-File-Path-2.09-2.el7.noarch.rpm                                                                             |  26 kB  00:00:00     
(7/38): perl-File-Temp-0.23.01-3.el7.noarch.rpm                                                                          |  56 kB  00:00:00     
(8/38): perl-Encode-2.51-7.el7.x86_64.rpm                                                                                | 1.5 MB  00:00:00     
(9/38): perl-Filter-1.49-3.el7.x86_64.rpm                                                                                |  76 kB  00:00:00     
(10/38): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm                                                                           |  38 kB  00:00:00     
(11/38): perl-Getopt-Long-2.40-3.el7.noarch.rpm                                                                          |  56 kB  00:00:00     
(12/38): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm                                                                          |  87 kB  00:00:00     
(13/38): perl-Pod-Simple-3.28-4.el7.noarch.rpm                                                                           | 216 kB  00:00:00     
(14/38): perl-PathTools-3.40-5.el7.x86_64.rpm                                                                            |  82 kB  00:00:00     
(15/38): perl-Pod-Usage-1.63-3.el7.noarch.rpm                                                                            |  27 kB  00:00:00     
(16/38): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm                                                                  |  36 kB  00:00:00     
Public key for perl-5.16.3-299.el7_9.x86_64.rpm is not installed
(17/38): perl-5.16.3-299.el7_9.x86_64.rpm                                                                                | 8.0 MB  00:00:01     
(18/38): perl-Pod-Escapes-1.04-299.el7_9.noarch.rpm                                                                      |  52 kB  00:00:00     
(19/38): perl-Socket-2.010-5.el7.x86_64.rpm                                                                              |  49 kB  00:00:00     
(20/38): perl-Storable-2.45-3.el7.x86_64.rpm                                                                             |  77 kB  00:00:00     
(21/38): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm                                                                         |  45 kB  00:00:00     
(22/38): perl-Text-ParseWords-3.29-4.el7.noarch.rpm                                                                      |  14 kB  00:00:00     
(23/38): perl-Time-Local-1.2300-2.el7.noarch.rpm                                                                         |  24 kB  00:00:00     
(24/38): perl-constant-1.27-2.el7.noarch.rpm                                                                             |  19 kB  00:00:00     
(25/38): perl-podlators-2.5.1-3.el7.noarch.rpm                                                                           | 112 kB  00:00:00     
(26/38): perl-parent-0.225-244.el7.noarch.rpm                                                                            |  12 kB  00:00:00     
(27/38): perl-threads-shared-1.43-6.el7.x86_64.rpm                                                                       |  39 kB  00:00:00     
(28/38): perl-macros-5.16.3-299.el7_9.x86_64.rpm                                                                         |  44 kB  00:00:00     
(29/38): psmisc-22.20-17.el7.x86_64.rpm                                                                                  | 141 kB  00:00:00     
(30/38): perl-libs-5.16.3-299.el7_9.x86_64.rpm                                                                           | 690 kB  00:00:00     
(31/38): perl-threads-1.87-4.el7.x86_64.rpm                                                                              |  49 kB  00:00:00     
(32/38): tree-1.6.0-10.el7.x86_64.rpm                                                                                    |  46 kB  00:00:00     
(33/38): vim-enhanced-7.4.629-8.el7_9.x86_64.rpm                                                                         | 1.1 MB  00:00:00     
(34/38): vim-filesystem-7.4.629-8.el7_9.x86_64.rpm                                                                       |  11 kB  00:00:00     
(35/38): which-2.20-7.el7.x86_64.rpm                                                                                     |  41 kB  00:00:00     
(36/38): wget-1.14-18.el7_6.1.x86_64.rpm                                                                                 | 547 kB  00:00:00     
(37/38): vim-common-7.4.629-8.el7_9.x86_64.rpm                                                                           | 5.9 MB  00:00:00     
(38/38): groff-base-1.22.2-8.el7.x86_64.rpm                                                                              | 942 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                           7.0 MB/s |  20 MB  00:00:02     
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 From       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gpm-libs-1.20.7-6.el7.x86_64                                                                                                1/38 
  Installing : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                                                                                     2/38 
  Installing : 2:vim-common-7.4.629-8.el7_9.x86_64                                                                                         3/38 
  Installing : which-2.20-7.el7.x86_64                                                                                                     4/38 
install-info: No such file or directory for /usr/share/info/which.info.gz
  Installing : groff-base-1.22.2-8.el7.x86_64                                                                                              5/38 
  Installing : 1:perl-parent-0.225-244.el7.noarch                                                                                          6/38 
  Installing : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                           7/38 
  Installing : perl-podlators-2.5.1-3.el7.noarch                                                                                           8/38 
  Installing : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                          9/38 
  Installing : 1:perl-Pod-Escapes-1.04-299.el7_9.noarch                                                                                   10/38 
  Installing : perl-Encode-2.51-7.el7.x86_64                                                                                              11/38 
  Installing : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                     12/38 
  Installing : perl-Pod-Usage-1.63-3.el7.noarch                                                                                           13/38 
  Installing : 4:perl-macros-5.16.3-299.el7_9.x86_64                                                                                      14/38 
  Installing : perl-Storable-2.45-3.el7.x86_64                                                                                            15/38 
  Installing : perl-Exporter-5.68-3.el7.noarch                                                                                            16/38 
  Installing : perl-constant-1.27-2.el7.noarch                                                                                            17/38 
  Installing : perl-Socket-2.010-5.el7.x86_64                                                                                             18/38 
  Installing : perl-Time-Local-1.2300-2.el7.noarch                                                                                        19/38 
  Installing : perl-Carp-1.26-244.el7.noarch                                                                                              20/38 
  Installing : perl-PathTools-3.40-5.el7.x86_64                                                                                           21/38 
  Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                 22/38 
  Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                        23/38 
  Installing : perl-File-Temp-0.23.01-3.el7.noarch                                                                                        24/38 
  Installing : perl-File-Path-2.09-2.el7.noarch                                                                                           25/38 
  Installing : perl-threads-shared-1.43-6.el7.x86_64                                                                                      26/38 
  Installing : perl-threads-1.87-4.el7.x86_64                                                                                             27/38 
  Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                      28/38 
  Installing : perl-Filter-1.49-3.el7.x86_64                                                                                              29/38 
  Installing : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                        30/38 
  Installing : perl-Getopt-Long-2.40-3.el7.noarch                                                                                         31/38 
  Installing : 4:perl-5.16.3-299.el7_9.x86_64                                                                                             32/38 
  Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                                                                                      33/38 
  Installing : psmisc-22.20-17.el7.x86_64                                                                                                 34/38 
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                                35/38 
install-info: No such file or directory for /usr/share/info/wget.info.gz
  Installing : 1:bash-completion-2.1-8.el7.noarch                                                                                         36/38 
  Installing : tree-1.6.0-10.el7.x86_64                                                                                                   37/38 
  Installing : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                  38/38 
  Verifying  : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                           1/38 
  Verifying  : perl-threads-shared-1.43-6.el7.x86_64                                                                                       2/38 
  Verifying  : perl-Storable-2.45-3.el7.x86_64                                                                                             3/38 
  Verifying  : groff-base-1.22.2-8.el7.x86_64                                                                                              4/38 
  Verifying  : perl-Exporter-5.68-3.el7.noarch                                                                                             5/38 
  Verifying  : perl-constant-1.27-2.el7.noarch                                                                                             6/38 
  Verifying  : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                                                                                       7/38 
  Verifying  : 4:perl-macros-5.16.3-299.el7_9.x86_64                                                                                       8/38 
  Verifying  : perl-PathTools-3.40-5.el7.x86_64                                                                                            9/38 
  Verifying  : 1:perl-parent-0.225-244.el7.noarch                                                                                         10/38 
  Verifying  : perl-Socket-2.010-5.el7.x86_64                                                                                             11/38 
  Verifying  : which-2.20-7.el7.x86_64                                                                                                    12/38 
  Verifying  : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                                                                                    13/38 
  Verifying  : perl-File-Temp-0.23.01-3.el7.noarch                                                                                        14/38 
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                  15/38 
  Verifying  : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                        16/38 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                                                   17/38 
  Verifying  : perl-Time-Local-1.2300-2.el7.noarch                                                                                        18/38 
  Verifying  : 1:perl-Pod-Escapes-1.04-299.el7_9.noarch                                                                                   19/38 
  Verifying  : perl-Carp-1.26-244.el7.noarch                                                                                              20/38 
  Verifying  : 1:bash-completion-2.1-8.el7.noarch                                                                                         21/38 
  Verifying  : 2:vim-common-7.4.629-8.el7_9.x86_64                                                                                        22/38 
  Verifying  : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                 23/38 
  Verifying  : perl-Pod-Usage-1.63-3.el7.noarch                                                                                           24/38 
  Verifying  : perl-Encode-2.51-7.el7.x86_64                                                                                              25/38 
  Verifying  : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                         26/38 
  Verifying  : perl-podlators-2.5.1-3.el7.noarch                                                                                          27/38 
  Verifying  : 4:perl-5.16.3-299.el7_9.x86_64                                                                                             28/38 
  Verifying  : perl-File-Path-2.09-2.el7.noarch                                                                                           29/38 
  Verifying  : perl-threads-1.87-4.el7.x86_64                                                                                             30/38 
  Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                      31/38 
  Verifying  : gpm-libs-1.20.7-6.el7.x86_64                                                                                               32/38 
  Verifying  : perl-Filter-1.49-3.el7.x86_64                                                                                              33/38 
  Verifying  : perl-Getopt-Long-2.40-3.el7.noarch                                                                                         34/38 
  Verifying  : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                     35/38 
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                                36/38 
  Verifying  : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                        37/38 
  Verifying  : psmisc-22.20-17.el7.x86_64                                                                                                 38/38 

Installed:
  bash-completion.noarch 1:2.1-8.el7     net-tools.x86_64 0:2.0-0.25.20131004git.el7  psmisc.x86_64 0:22.20-17.el7  tree.x86_64 0:1.6.0-10.el7 
  vim-enhanced.x86_64 2:7.4.629-8.el7_9  wget.x86_64 0:1.14-18.el7_6.1               

Dependency Installed:
  gpm-libs.x86_64 0:1.20.7-6.el7                 groff-base.x86_64 0:1.22.2-8.el7                   perl.x86_64 4:5.16.3-299.el7_9             
  perl-Carp.noarch 0:1.26-244.el7                perl-Encode.x86_64 0:2.51-7.el7                    perl-Exporter.noarch 0:5.68-3.el7          
  perl-File-Path.noarch 0:2.09-2.el7             perl-File-Temp.noarch 0:0.23.01-3.el7              perl-Filter.x86_64 0:1.49-3.el7            
  perl-Getopt-Long.noarch 0:2.40-3.el7           perl-HTTP-Tiny.noarch 0:0.033-3.el7                perl-PathTools.x86_64 0:3.40-5.el7         
  perl-Pod-Escapes.noarch 1:1.04-299.el7_9       perl-Pod-Perldoc.noarch 0:3.20-4.el7               perl-Pod-Simple.noarch 1:3.28-4.el7        
  perl-Pod-Usage.noarch 0:1.63-3.el7             perl-Scalar-List-Utils.x86_64 0:1.27-248.el7       perl-Socket.x86_64 0:2.010-5.el7           
  perl-Storable.x86_64 0:2.45-3.el7              perl-Text-ParseWords.noarch 0:3.29-4.el7           perl-Time-HiRes.x86_64 4:1.9725-3.el7      
  perl-Time-Local.noarch 0:1.2300-2.el7          perl-constant.noarch 0:1.27-2.el7                  perl-libs.x86_64 4:5.16.3-299.el7_9        
  perl-macros.x86_64 4:5.16.3-299.el7_9          perl-parent.noarch 1:0.225-244.el7                 perl-podlators.noarch 0:2.5.1-3.el7        
  perl-threads.x86_64 0:1.87-4.el7               perl-threads-shared.x86_64 0:1.43-6.el7            vim-common.x86_64 2:7.4.629-8.el7_9        
  vim-filesystem.x86_64 2:7.4.629-8.el7_9        which.x86_64 0:2.20-7.el7                         

Complete!

 

 

2.3、在容器内安装配置nginx,生成业务数据,设置服务前台运行

## 安装epel源
[root@502a7a7faae8 /]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2023-04-24 14:23:54--  https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 120.226.58.184, 120.226.58.182, 120.226.58.185, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|120.226.58.184|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: \'/etc/yum.repos.d/epel.repo\'

100%[======================================================================================================>] 664         --.-K/s   in 0s      

2023-04-24 14:23:54 (124 MB/s) - \'/etc/yum.repos.d/epel.repo\' saved [664/664]

[root@502a7a7faae8 /]# yum makecache fast
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                     | 3.6 kB  00:00:00     
epel                                                                                                                     | 4.7 kB  00:00:00     
extras                                                                                                                   | 2.9 kB  00:00:00     
updates                                                                                                                  | 2.9 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                                                              |  99 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                                                                                            | 1.0 MB  00:00:00     
(3/3): epel/x86_64/primary_db                                               

docker镜像管理和容器管理以及制作本地仓库

1. 镜像管理
    1.1 获取镜像
    docker search centos
    docker pull centos:6.9
    docker pull centos:7.5.1804
    docker pull nginx
    1.2 查询镜像
    docker images
    docker images -q 
    docker inspect ID/name:tag
    1.3 删除镜像
    docker rmi  ID 
    docker rmi `docker images -q`
    docker rmi $(docker images -q)
    
    1.4 导入导出镜像
    [root@docker ~]# docker image save nginx >/opt/nginx.tar.gz
    [root@docker ~]# docker image load -i /opt/nginx.tar.gz
    
    
    1.5 启动容器并获取镜像
    [root@docker ~]# docker  run -d -p 80:80 httpd
    [root@docker ~]# docker ps -a
    [root@docker ~]# docker images
    
    
    1.6 docker一步一步学习制作镜像
        语法:
        第一个镜像创建:
        docker ps -a 
        docker commit xxxxxx oldguo/wordpress:v1
        docker images 
    

制作镜像: centos7.5+vim+net-tools+iproute+sshd

1.启动新容器
docker run -it --name "centos7.5" 76d6bc25b8a5

2.优化yum源
mv /etc/yum.repos.d/*.repo /tmp
echo -e "[ftp]
name=ftp
baseurl=ftp://10.0.0.100/pub/centos7
gpgcheck=0">/etc/yum.repos.d/ftp.repo

3. 安装必须软件包

yum install -y vim net-tools  iproute   openssh-*   -y


4.启动SSHD

 mkdir /var/run/sshd
 echo UseDNS no >> /etc/ssh/sshd_config
 sed -i -e /pam_loginuid.so/d /etc/pam.d/sshd
 echo root:123456 | chpasswd
 /usr/bin/ssh-keygen -A
 /usr/sbin/sshd -D 
 
 
 注意: 以上操作做完之后,会一直不退出,需要用以下命令退回到宿主机,并不关闭容器
 ctrl p  q

5.制作镜像
docker commit centos7.5 oldguo/centos7_sshd:v2



## Centos7.5
[root@docker sshd]# vim  dockerfile 
FROM centos:7.5.1804
RUN mv /etc/yum.repos.d/*.repo /tmp
RUN echo -e "[ftp]
name=ftp
baseurl=ftp://10.0.0.100/pub/centos7
gpgcheck=0">/etc/yum.repos.d/ftp.repo
RUN yum install -y openssh-server
RUN yum install -y openssh-clients
RUN yum install net-tools* -y
RUN yum install iproute-* -y
RUN mkdir /var/run/sshd
RUN echo UseDNS no >> /etc/ssh/sshd_config
RUN sed -i -e /pam_loginuid.so/d /etc/pam.d/sshd
RUN echo root:123456 | chpasswd
RUN /usr/bin/ssh-keygen -A
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

docker build -t "oldguo/centos7_sshd:v3" /opt/dockerfile


===========================================
2. 容器基本管理        
    2.0 容器的类型
        工具类:vim
             docker run -it --name="test_vim"  3fe2fe0dab2e /bin/bash
        服务类:nginx 
            docker run -d -p 8080:80 --name="discuz" nginx:1.14

    2.1 容器的多类启动方式
     (1)交互式启动
     [root@docker ~]# docker run -it --name "testcentos" centos:6.9 /bin/bash
     主要是针对于工具类的容器,一旦exit容器,容器就自动关闭
     (2)守护式启动
      1.交互式启动容器+Ctrl+p+q
      [root@docker ~]# docker run  -it --name "testnginx" nginx /bin/bash
      加ctrl+p+q
        [root@docker ~]# docker attach testnginx
      2.死循环
     docker run  --name testnginx1  -d nginx /bin/sh -c "while true ;do echo hello world; sleep 1;done"
      3.服务前台运行
       sshd -D  
       nginx -g ""
  
       hang 夯住
      
    2.2 容器的常用管理命令
    docker ps -a  -q -l
    
    docker rm 容器ID|容器名称
    批量删除已关闭
    docker rm -v $(docker ps -aq -f status=exited)
    批量强制删除所有
    docker rm -f `docker ps -a –q`
    
    docker top nginx
    docker inspect nginx
    docker attach 容器ID|容器名称(工具类)配合ctrl+p+q
    docker exec  -i -t  容器ID|容器名称 /bin/bash(服务类),一般是做服务类容器调试用
    [root@docker ~]# docker exec -it  centos6.9   /bin/bash


    docker stop
    docker kill

    docker  start -i
    docker  restart 容器ID|容器名称

    
    
3. 数据卷的使用(持久化)


    

4.制作私有仓库

4.1 配置私有仓库

docker run -d -p 5000:5000 --restart=always --name registry -v /opt/Registry:/var/lib/registry  registry


vim /etc/docker/daemon.json

{
   "registry-mirrors": ["https://68rmyzg7.mirror.aliyuncs.com"],
   "insecure-registries": ["10.0.0.100:5000"]
}


systemctl  restart docker
    
    
    
4.2 使用本地镜像:
4.2.1 制作本地镜像并push到

[root@docker ~]# docker tag nginx 10.0.0.100:5000/oldguo/nginx:v1
[root@docker ~]# docker images
[root@docker ~]# docker push 10.0.0.100:5000/oldguo/nginx:v1

4.2.2 异地进行pull镜像
[root@docker ~]# docker pull  10.0.0.100:5000/oldguo/nginx:v1    
    
    


故障转移:(高可用)

1.主备系统   
      
      

 

以上是关于Docker镜像制作和管理的主要内容,如果未能解决你的问题,请参考以下文章

Docker images详细介绍及管理制作镜像

Docker镜像管理基础与基于容器的镜像制作示例

docker镜像管理基础

docker镜像管理基础

docker镜像管理基础

Docker镜像管理2之nginx镜像制作