• docker镜像操作


    仓库配置文件默认值为docker官方镜像地址

    # cat /etc/docker/daemon.json 
    {
      "registry-mirror": [
        "https://registry.docker-cn.com"
      ]
    }

    查找镜像

    # docker search centos
    NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    centos                             The official build of CentOS.                   5615                [OK]                
    ansible/centos7-ansible            Ansible on Centos7                              124                                     [OK]
    jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos - …   113                                     [OK]
    consol/centos-xfce-vnc             Centos container with "headless" VNC session…   99                                      [OK]
    centos/mysql-57-centos7            MySQL 5.7 SQL database server                   63                                      
    imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              57                                      [OK]
    tutum/centos                       Simple CentOS docker image with SSH access      44                                      
    centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   39                                      
    kinogmt/centos-ssh                 CentOS with SSH                                 29                                      [OK]
    centos/php-56-centos7              Platform for building and running PHP 5.6 ap…   22                                      
    pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   10                                      
    drecom/centos-ruby                 centos ruby                                     6                                       [OK]
    centos/tools                       Docker image that has systems administration…   4                                       [OK]
    darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
    mamohr/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                                       [OK]
    pivotaldata/centos                 Base centos, freshened up a little with a Do…   3                                       
    pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   2                                       
    miko2u/centos6                     CentOS6 日本語環境                                   2                                       [OK]
    pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   2                                       
    mcnaughton/centos-base             centos base image                               1                                       [OK]
    indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developmen…   1                                       [OK]
    blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
    pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0                                       
    smartentry/centos                  centos with smartentry                          0                                       [OK]
    pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0                                       

    下载指定的centos镜像

    # docker pull centos
    Using default tag: latest
    latest: Pulling from library/centos
    729ec3a6ada3: Pull complete 
    Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
    Status: Downloaded newer image for centos:latest
    docker.io/library/centos:latest

    查看下载的镜像

    # docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos              latest              0f3e07c0138f        2 weeks ago         220MB

    为镜像添加一个新的tag

    # docker tag centos:latest centos:version7
    # docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos              latest              0f3e07c0138f        2 weeks ago         220MB
    centos              version7            0f3e07c0138f        2 weeks ago         220MB

    删除镜像

    (如果一个镜像有多个flag时,删除镜像仅仅删除该镜像对应的flag,镜像本身并未删除。)

    # docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos              latest              0f3e07c0138f        2 weeks ago         220MB
    centos              version7            0f3e07c0138f        2 weeks ago         220MB
    # docker rmi centos:latest
    Untagged: centos:latest
    # docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos              version7            0f3e07c0138f        2 weeks ago         220MB

     查看镜像详细信息

    # docker inspect 0f3e07c0138f

    输出

    [
        {
            "Id": "sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da",
            "RepoTags": [
                "centos:version7"
            ],
            "RepoDigests": [
                "centos@sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9"
            ],
            "Parent": "",
            "Comment": "",
            "Created": "2019-10-01T23:19:57.105928163Z",
            "Container": "711572e3c0c1ac06d5c13c4e668ec170b8ad8786b5f0949f884a5f7fd350d856",
            "ContainerConfig": {
                "Hostname": "711572e3c0c1",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "#(nop) ",
                    "CMD ["/bin/bash"]"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:c0bda62fdbad65a3c6a1843d293a3a47d8233115cc6d384e3cb07c53580a2b43",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {
                    "org.label-schema.build-date": "20190927",
                    "org.label-schema.license": "GPLv2",
                    "org.label-schema.name": "CentOS Base Image",
                    "org.label-schema.schema-version": "1.0",
                    "org.label-schema.vendor": "CentOS"
                }
            },
            "DockerVersion": "18.06.1-ce",
            "Author": "",
            "Config": {
                "Hostname": "",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/bin/bash"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:c0bda62fdbad65a3c6a1843d293a3a47d8233115cc6d384e3cb07c53580a2b43",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {
                    "org.label-schema.build-date": "20190927",
                    "org.label-schema.license": "GPLv2",
                    "org.label-schema.name": "CentOS Base Image",
                    "org.label-schema.schema-version": "1.0",
                    "org.label-schema.vendor": "CentOS"
                }
            },
            "Architecture": "amd64",
            "Os": "linux",
            "Size": 219583055,
            "VirtualSize": 219583055,
            "GraphDriver": {
                "Data": {
                    "MergedDir": "/usr/local/docker/overlay2/f533f3b264a3098e4a79a0f40778566ea2b10c7dfb422d57d5c8760aba3e2723/merged",
                    "UpperDir": "/usr/local/docker/overlay2/f533f3b264a3098e4a79a0f40778566ea2b10c7dfb422d57d5c8760aba3e2723/diff",
                    "WorkDir": "/usr/local/docker/overlay2/f533f3b264a3098e4a79a0f40778566ea2b10c7dfb422d57d5c8760aba3e2723/work"
                },
                "Name": "overlay2"
            },
            "RootFS": {
                "Type": "layers",
                "Layers": [
                    "sha256:9e607bb861a7d58bece26dd2c02874beedd6a097c1b6eca5255d5eb0d2236983"
                ]
            },
            "Metadata": {
                "LastTagTime": "2019-10-16T23:31:58.386336955+08:00"
            }
        }
    ]

     创建镜像

    基于container创建镜像

    首先基于镜像创建一个容器,并在容器添加新文件

    # docker run --hostname web --name web-container -it centos:version7 /bin/bash
    [root@web /]# cd /usr/local/
    [root@web local]# mkdir www
    [root@web local]# cd www/
    [root@web www]# cp -r /etc/* .
    # docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    6eb1f9a40fab        centos:version7     "/bin/bash"         44 seconds ago      Up 43 seconds                           web-container

    可以看到当前有一个正在运行的容器web-container,并已经写入新数据,现在将基于该容器创建一个新的镜像文件

    # docker commit --author "Crist Lee(crist.lee@tnave.com)" --message "Add new web files." web-container centos:web
    sha256:abfc8b292519afd833a8ec816dc64d1b8fa1067241e680efdf7fe563276d5d79
    # docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos              web                 abfc8b292519        5 seconds ago       221MB
    centos              version7            0f3e07c0138f        2 weeks ago         220MB

    基于dockfile创建镜像

    FROM centos:version7.1
    LABEL author="Crist.Lee@telna.com" date="2019-10-17"
    LABEL description="This is an image with mysql version5.7.18 binary installed"
    LABEL version="centos7-mysql-v5.7.18"
    ENV MYSQL_HOME=/usr/local/mysql
    ENV PATH ${MYSQL_HOME}/bin:$PATH
    EXPOSE 3306
    RUN yum -y install libaio openssl openssl-devel
    RUN mkdir -p ${MYSQL_HOME}/arch
    RUN groupadd -r dba && useradd -r -g dba -G root -d /usr/local/mysql mysqladmin
    WORKDIR ${MYSQL_HOME}
    RUN wget https://downloads.mysql.com/archives/get/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.7.18-linux-glibc2.5-x86_64/* . && rm -rf mysql-5.7.18-linux-glibc2.5-x86_64
    RUN cp support-files/mysql.server /etc/init.d/mysql && chown mysqladmin.dba /etc/init.d/mysql && chmod +x /etc/init.d/mysql
    RUN chown -R mysqladmin.dba /usr/local/mysql
    RUN rm -rf /etc/my.cnf
    ADD my.cnf /etc/
    RUN chown mysqladmin.dba /etc/my.cnf
    USER mysqladmin
    RUN bin/mysqld --initialize --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && /etc/init.d/mysql start

     my.cnf

    [client]
    port            = 3306
    socket          = /usr/local/mysql/data/mysql.sock
     
    [mysqld]
    port            = 3306
    socket          = /usr/local/mysql/data/mysql.sock
    
    skip-external-locking
    key_buffer_size = 256M
    sort_buffer_size = 2M
    read_buffer_size = 2M
    read_rnd_buffer_size = 4M
    query_cache_size= 32M
    max_allowed_packet = 16M
    myisam_sort_buffer_size=128M
    tmp_table_size=32M
    
    table_open_cache = 1024
    thread_cache_size = 8
    #wait_timeout = 86400
    #interactive_timeout = 86400
    max_connections = 1000
    wait_timeout = 28800
    interactive_timeout = 28800
    
    #isolation level and default engine 
    default-storage-engine = INNODB
    transaction-isolation = READ-COMMITTED
    
    server-id  = 1
    basedir     = /usr/local/mysql
    datadir     = /usr/local/mysql/data
    pid-file     = /usr/local/mysql/data/hostname.pid
    
    #open performance schema
    log-warnings
    sysdate-is-now
    log_timestamps=SYSTEM
    log-error-verbosity = 3
    
    binlog_format = MIXED
    log_bin_trust_function_creators=1
    log-error  = /usr/local/mysql/data/hostname.err
    log-bin=/usr/local/mysql/arch/mysql-bin
    #other logs
    #general_log =1
    #general_log_file  = /usr/local/mysql/data/general_log.err
    #slow_query_log=1
    #slow_query_log_file=/usr/local/mysql/data/slow_log.err
    
    #for replication slave
    #log-slave-updates 
    #sync_binlog = 1
    
    #for innodb options 
    innodb_data_home_dir = /usr/local/mysql/data/
    innodb_data_file_path = ibdata1:500M:autoextend
    innodb_log_group_home_dir = /usr/local/mysql/arch
    innodb_log_files_in_group = 2
    innodb_log_file_size = 200M
    
    innodb_buffer_pool_size = 1024M
    #innodb_additional_mem_pool_size = 50M
    innodb_log_buffer_size = 16M
    
    innodb_lock_wait_timeout = 100
    #innodb_thread_concurrency = 0
    innodb_flush_log_at_trx_commit = 1
    
    #innodb io features: add for mysql5.5.8
    performance_schema
    innodb_read_io_threads=4
    innodb-write-io-threads=4
    innodb-io-capacity=200
    #purge threads change default(0) to 1 for purge
    innodb_purge_threads=1
    innodb_use_native_aio=on
    
    #case-sensitive file names and separate tablespace
    innodb_file_per_table = 1
    lower_case_table_names=1
    
    secure-file-priv = ""
    explicit_defaults_for_timestamp = 1
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysql]
    no-auto-rehash
    
    [mysqlhotcopy]
    interactive-timeout
    
    [myisamchk]
    key_buffer_size = 256M
    sort_buffer_size = 256M
    read_buffer = 2M
    write_buffer = 2M
    View Code

     dockerfile生成镜像

    # docker build --tag cenots/centos7-mysql57 .
    Sending build context to Docker daemon  6.144kB
    Step 1/19 : FROM centos:version7.1
     ---> babd2f913fc9
    Step 2/19 : LABEL author="Crist.Lee@telna.com" date="2019-10-17"
     ---> Running in 36a39d67a4ad
    Removing intermediate container 36a39d67a4ad
     ---> 0f6b629d5aee
    Step 3/19 : LABEL description="This is an image with mysql version5.7.18 binary installed"
     ---> Running in 62ebd642e434
    Removing intermediate container 62ebd642e434
     ---> 2f39a121c973
    Step 4/19 : LABEL version="centos7-mysql-v5.7.18"
     ---> Running in 41ee87349bc4
    Removing intermediate container 41ee87349bc4
     ---> 6cdef162e063
    Step 5/19 : ENV MYSQL_HOME=/usr/local/mysql
     ---> Running in 0198fb6166c6
    Removing intermediate container 0198fb6166c6
     ---> 9b9a106f6334
    Step 6/19 : ENV PATH ${MYSQL_HOME}/bin:$PATH
     ---> Running in 6eab2ccb13ed
    Removing intermediate container 6eab2ccb13ed
     ---> c07761bfff47
    Step 7/19 : EXPOSE 3306
     ---> Running in 278b6e9e1bee
    Removing intermediate container 278b6e9e1bee
     ---> 27c5a433bfea
    Step 8/19 : RUN yum -y install libaio openssl openssl-devel
     ---> Running in f44421646075
    Last metadata expiration check: 19:29:42 ago on Fri Oct 18 15:08:42 2019.
    Dependencies resolved.
    ================================================================================
     Package                   Arch         Version              Repository    Size
    ================================================================================
    Installing:
     libaio                    x86_64       0.3.110-12.el8       BaseOS        32 k
     openssl                   x86_64       1:1.1.1-8.el8        BaseOS       664 k
     openssl-devel             x86_64       1:1.1.1-8.el8        BaseOS       2.3 M
    Installing dependencies:
     keyutils-libs-devel       x86_64       1.5.10-6.el8         BaseOS        48 k
     krb5-devel                x86_64       1.16.1-22.el8        BaseOS       546 k
     libcom_err-devel          x86_64       1.44.3-2.el8         BaseOS        37 k
     libkadm5                  x86_64       1.16.1-22.el8        BaseOS       184 k
     libselinux-devel          x86_64       2.8-6.el8            BaseOS       199 k
     libsepol-devel            x86_64       2.8-2.el8            BaseOS        85 k
     libverto-devel            x86_64       0.3.0-5.el8          BaseOS        18 k
     pcre2-devel               x86_64       10.32-1.el8          BaseOS       605 k
     pcre2-utf16               x86_64       10.32-1.el8          BaseOS       228 k
     pcre2-utf32               x86_64       10.32-1.el8          BaseOS       220 k
     zlib-devel                x86_64       1.2.11-10.el8        BaseOS        56 k
    
    Transaction Summary
    ================================================================================
    Install  14 Packages
    
    Total download size: 5.1 M
    Installed size: 9.3 M
    Downloading Packages:
    (1/14): keyutils-libs-devel-1.5.10-6.el8.x86_64  29 kB/s |  48 kB     00:01    
    (2/14): libaio-0.3.110-12.el8.x86_64.rpm         19 kB/s |  32 kB     00:01    
    (3/14): krb5-devel-1.16.1-22.el8.x86_64.rpm     246 kB/s | 546 kB     00:02    
    (4/14): libcom_err-devel-1.44.3-2.el8.x86_64.rp  54 kB/s |  37 kB     00:00    
    (5/14): libkadm5-1.16.1-22.el8.x86_64.rpm       221 kB/s | 184 kB     00:00    
    (6/14): libsepol-devel-2.8-2.el8.x86_64.rpm     121 kB/s |  85 kB     00:00    
    (7/14): libverto-devel-0.3.0-5.el8.x86_64.rpm    31 kB/s |  18 kB     00:00    
    (8/14): libselinux-devel-2.8-6.el8.x86_64.rpm   205 kB/s | 199 kB     00:00    
    (9/14): pcre2-devel-10.32-1.el8.x86_64.rpm      626 kB/s | 605 kB     00:00    
    (10/14): openssl-1.1.1-8.el8.x86_64.rpm         535 kB/s | 664 kB     00:01    
    (11/14): openssl-devel-1.1.1-8.el8.x86_64.rpm   1.3 MB/s | 2.3 MB     00:01    
    (12/14): pcre2-utf16-10.32-1.el8.x86_64.rpm     328 kB/s | 228 kB     00:00    
    (13/14): pcre2-utf32-10.32-1.el8.x86_64.rpm     197 kB/s | 220 kB     00:01    
    (14/14): zlib-devel-1.2.11-10.el8.x86_64.rpm     87 kB/s |  56 kB     00:00    
    --------------------------------------------------------------------------------
    Total                                           733 kB/s | 5.1 MB     00:07     
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                        1/1 
      Installing       : zlib-devel-1.2.11-10.el8.x86_64                       1/14 
      Installing       : pcre2-utf32-10.32-1.el8.x86_64                        2/14 
      Installing       : pcre2-utf16-10.32-1.el8.x86_64                        3/14 
      Installing       : pcre2-devel-10.32-1.el8.x86_64                        4/14 
      Installing       : libverto-devel-0.3.0-5.el8.x86_64                     5/14 
      Installing       : libsepol-devel-2.8-2.el8.x86_64                       6/14 
      Installing       : libselinux-devel-2.8-6.el8.x86_64                     7/14 
      Installing       : libkadm5-1.16.1-22.el8.x86_64                         8/14 
      Installing       : libcom_err-devel-1.44.3-2.el8.x86_64                  9/14 
      Installing       : keyutils-libs-devel-1.5.10-6.el8.x86_64              10/14 
      Installing       : krb5-devel-1.16.1-22.el8.x86_64                      11/14 
      Installing       : openssl-devel-1:1.1.1-8.el8.x86_64                   12/14 
      Installing       : openssl-1:1.1.1-8.el8.x86_64                         13/14 
      Installing       : libaio-0.3.110-12.el8.x86_64                         14/14 
      Running scriptlet: libaio-0.3.110-12.el8.x86_64                         14/14 
      Verifying        : keyutils-libs-devel-1.5.10-6.el8.x86_64               1/14 
      Verifying        : krb5-devel-1.16.1-22.el8.x86_64                       2/14 
      Verifying        : libaio-0.3.110-12.el8.x86_64                          3/14 
      Verifying        : libcom_err-devel-1.44.3-2.el8.x86_64                  4/14 
      Verifying        : libkadm5-1.16.1-22.el8.x86_64                         5/14 
      Verifying        : libselinux-devel-2.8-6.el8.x86_64                     6/14 
      Verifying        : libsepol-devel-2.8-2.el8.x86_64                       7/14 
      Verifying        : libverto-devel-0.3.0-5.el8.x86_64                     8/14 
      Verifying        : openssl-1:1.1.1-8.el8.x86_64                          9/14 
      Verifying        : openssl-devel-1:1.1.1-8.el8.x86_64                   10/14 
      Verifying        : pcre2-devel-10.32-1.el8.x86_64                       11/14 
      Verifying        : pcre2-utf16-10.32-1.el8.x86_64                       12/14 
      Verifying        : pcre2-utf32-10.32-1.el8.x86_64                       13/14 
      Verifying        : zlib-devel-1.2.11-10.el8.x86_64                      14/14 
    
    Installed:
      libaio-0.3.110-12.el8.x86_64         openssl-1:1.1.1-8.el8.x86_64             
      openssl-devel-1:1.1.1-8.el8.x86_64   keyutils-libs-devel-1.5.10-6.el8.x86_64  
      krb5-devel-1.16.1-22.el8.x86_64      libcom_err-devel-1.44.3-2.el8.x86_64     
      libkadm5-1.16.1-22.el8.x86_64        libselinux-devel-2.8-6.el8.x86_64        
      libsepol-devel-2.8-2.el8.x86_64      libverto-devel-0.3.0-5.el8.x86_64        
      pcre2-devel-10.32-1.el8.x86_64       pcre2-utf16-10.32-1.el8.x86_64           
      pcre2-utf32-10.32-1.el8.x86_64       zlib-devel-1.2.11-10.el8.x86_64          
    
    Complete!
    Removing intermediate container f44421646075
     ---> af13398cbacc
    Step 9/19 : RUN mkdir -p ${MYSQL_HOME}/arch
     ---> Running in a3395e8668d1
    Removing intermediate container a3395e8668d1
     ---> 6a1768184818
    Step 10/19 : RUN groupadd -r dba && useradd -r -g dba -G root -d /usr/local/mysql mysqladmin
     ---> Running in aa7cdb4d7b44
    Removing intermediate container aa7cdb4d7b44
     ---> 70510352f29a
    Step 11/19 : WORKDIR ${MYSQL_HOME}
     ---> Running in 358db3f333dd
    Removing intermediate container 358db3f333dd
     ---> d26ee9868d39
    Step 12/19 : RUN wget https://downloads.mysql.com/archives/get/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.7.18-linux-glibc2.5-x86_64/* . && rm -rf mysql-5.7.18-linux-glibc2.5-x86_64
     ---> Running in 745256d95113
    --2019-10-19 10:38:49--  https://downloads.mysql.com/archives/get/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
    Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
    Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz [following]
    --2019-10-19 10:38:51--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
    Resolving cdn.mysql.com (cdn.mysql.com)... 184.29.107.217
    Connecting to cdn.mysql.com (cdn.mysql.com)|184.29.107.217|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 654430368 (624M) [application/x-tar-gz]
    Saving to: 'mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz'
    
    mysql-5.7.18-linux- 100%[===================>] 624.11M  8.58MB/s    in 77s     
    
    2019-10-19 10:40:09 (8.08 MB/s) - 'mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz' saved [654430368/654430368]
    
    Removing intermediate container 745256d95113
     ---> 5a1e9fc7b6db
    Step 13/19 : RUN cp support-files/mysql.server /etc/init.d/mysql && chown mysqladmin.dba /etc/init.d/mysql && chmod +x /etc/init.d/mysql
     ---> Running in 9a2694efc4d2
    Removing intermediate container 9a2694efc4d2
     ---> 987a7487ad8b
    Step 14/19 : RUN chown -R mysqladmin.dba /usr/local/mysql
     ---> Running in 46a26a9b8f73
    Removing intermediate container 46a26a9b8f73
     ---> db2b0b8f68d1
    Step 15/19 : RUN rm -rf /etc/my.cnf
     ---> Running in 83242d0d56ff
    Removing intermediate container 83242d0d56ff
     ---> fc9ac10be8b5
    Step 16/19 : ADD my.cnf /etc/
     ---> c37ee0d24f4f
    Step 17/19 : RUN chown mysqladmin.dba /etc/my.cnf
     ---> Running in 768c186de68c
    Removing intermediate container 768c186de68c
     ---> ccda398fc17c
    Step 18/19 : USER mysqladmin
     ---> Running in 2935c19fb4dc
    Removing intermediate container 2935c19fb4dc
     ---> cdf9ce503d15
    Step 19/19 : RUN bin/mysqld --initialize --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && /etc/init.d/mysql start
     ---> Running in af95b6c78b94
    Ignoring -days; not generating a certificate
    Generating a RSA private key
    .+++++
    .......+++++
    writing new private key to 'ca-key.pem'
    -----
    Ignoring -days; not generating a certificate
    Generating a RSA private key
    .......................................................................+++++
    ...+++++
    writing new private key to 'server-key.pem'
    -----
    Ignoring -days; not generating a certificate
    Generating a RSA private key
    .............................+++++
    ...+++++
    writing new private key to 'client-key.pem'
    -----
    Starting MySQL... SUCCESS! 
    Removing intermediate container af95b6c78b94
     ---> d46f0eee5c07
    Successfully built d46f0eee5c07
    Successfully tagged cenots/centos7-mysql57:latest

    查看生成的镜像文件和详情

    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        3 hours ago         7.94GB
    centos                   version7.1          babd2f913fc9        22 hours ago        262MB
    # docker history cenots/centos7-mysql57 --no-trunc
    IMAGE                                                                     CREATED             CREATED BY                                                                                                                                                                                                                                                SIZE                COMMENT
    sha256:d46f0eee5c07d4b75e2d90f321cfedfbcd7dde644ebbec7c45b40cd1d792ff31   3 hours ago         /bin/sh -c bin/mysqld --initialize --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data && /etc/init.d/mysql start                          970MB               
    sha256:cdf9ce503d152f029124e3a4995e3f460062eb126ab5c4168c3aa47a34c202e3   3 hours ago         /bin/sh -c #(nop)  USER mysqladmin                                                                                                                                                                                                                        0B                  
    sha256:ccda398fc17c61f0eb6df1d88d47fb6cc252a49a3b2f6e801b69ddce1cdbb3c6   3 hours ago         /bin/sh -c chown mysqladmin.dba /etc/my.cnf                                                                                                                                                                                                               2.27kB              
    sha256:c37ee0d24f4f3fb6bbef23375e4f049f69e3da316ff84a6f0a7fb36d7f07267f   3 hours ago         /bin/sh -c #(nop) ADD file:9dc8a34421f6f779baa90d697161be0aa8e19b18840dd9583166876c147c0f50 in /etc/                                                                                                                                                      2.27kB              
    sha256:fc9ac10be8b52653be54b9a86d765c231947331a39e541c383ccc0cce2ca6074   3 hours ago         /bin/sh -c rm -rf /etc/my.cnf                                                                                                                                                                                                                             0B                  
    sha256:db2b0b8f68d150ba81fe4435fc3e4edad46e04ac285970f36760bc4b26e4a5a0   3 hours ago         /bin/sh -c chown -R mysqladmin.dba /usr/local/mysql                                                                                                                                                                                                       3.34GB              
    sha256:987a7487ad8b3d2d485c796d9112f722f5fdcb052045852e6667b61e459da2b5   3 hours ago         /bin/sh -c cp support-files/mysql.server /etc/init.d/mysql && chown mysqladmin.dba /etc/init.d/mysql && chmod +x /etc/init.d/mysql                                                                                                                        10.6kB              
    sha256:5a1e9fc7b6dbd754057d92492f5aa55a6507761099e421d1dc1d9b985423f7cc   3 hours ago         /bin/sh -c wget https://downloads.mysql.com/archives/get/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.7.18-linux-glibc2.5-x86_64/* . && rm -rf mysql-5.7.18-linux-glibc2.5-x86_64   3.34GB              
    sha256:d26ee9868d390a29b242d1ca7280669a73c7bf17ba673dadacfce7f11cba1906   3 hours ago         /bin/sh -c #(nop) WORKDIR /usr/local/mysql                                                                                                                                                                                                                0B                  
    sha256:70510352f29a01fb0a107cc00ec1b0be0ac6f8d332cb12b60ae7f4c6ea569b8d   3 hours ago         /bin/sh -c groupadd -r dba && useradd -r -g dba -G root -d /usr/local/mysql mysqladmin                                                                                                                                                                    296kB               
    sha256:6a17681848182c6d3268def18123b4a3cc83b0113e91a3faf1be927cc18609bd   3 hours ago         /bin/sh -c mkdir -p ${MYSQL_HOME}/arch                                                                                                                                                                                                                    0B                  
    sha256:af13398cbacce477ed31498d2b471588f8d533773b2407e3b26ed01378e9e325   3 hours ago         /bin/sh -c yum -y install libaio openssl openssl-devel                                                                                                                                                                                                    39.7MB              
    sha256:27c5a433bfea2a618e571f27fac909f37b358935df6bf3d48b46aab289c2b70a   3 hours ago         /bin/sh -c #(nop)  EXPOSE 3306                                                                                                                                                                                                                            0B                  
    sha256:c07761bfff47b9658739580c9c370974103e70e03470bb9ba0a71929582a6938   3 hours ago         /bin/sh -c #(nop)  ENV PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin                                                                                                                                             0B                  
    sha256:9b9a106f6334cedb29e10e82449b5ed1c6545a48c3ff42c2999c4119d9dc93e6   3 hours ago         /bin/sh -c #(nop)  ENV MYSQL_HOME=/usr/local/mysql                                                                                                                                                                                                        0B                  
    sha256:6cdef162e0630085718aea5dc9f5519849c7c2dacf65e77d98d14d46bde38509   3 hours ago         /bin/sh -c #(nop)  LABEL version=centos7-mysql-v5.7.18                                                                                                                                                                                                    0B                  
    sha256:2f39a121c9736378953a48f647986b7278b725b9a0c67b9735ee992fda95f811   3 hours ago         /bin/sh -c #(nop)  LABEL description=This is an image with mysql version5.7.18 binary installed                                                                                                                                                           0B                  
    sha256:0f6b629d5aee8d03f6730bd92c8d0e0ed6a8aba5a5f5362a683f49a535472563   3 hours ago         /bin/sh -c #(nop)  LABEL author=Crist.Lee@telna.com date=2019-10-17                                                                                                                                                                                       0B                  
    sha256:babd2f913fc96c83587daf115c17227b10512b32ac10e99601684cfe453e26dd   23 hours ago        /bin/bash                                                                                                                                                                                                                                                 41.9MB              Add new web files.
    sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da   2 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]                                                                                                                                                                                                                      0B                  
    <missing>                                                                 2 weeks ago         /bin/sh -c #(nop)  LABEL org.label-schema.schema-version=1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20190927                                                   0B                  
    <missing>                                                                 2 weeks ago         /bin/sh -c #(nop) ADD file:d6fdacc1972df524a795bd36cf75dd355faefbe9a69d88d1fff95599e2eeed4c in /                                                                                                                                                          220MB               

    利用镜像创建容器

    docker run --hostname=mysql -name=mysql -it cenots/centos7-mysql57 /bin/bash
    24b2ccd981f4
    # docker ps 
    CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
    24b2ccd981f4        cenots/centos7-mysql57   "/bin/bash"         3 hours ago         Up 3 hours          3306/tcp            mysql

    此时进入容器默认以mysqladmin进入,如需要以root进入,执行

    # docker exec -it -u root mysql /bin/bash

     镜像导入和导出

    导出镜像

    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        3 hours ago         7.94GB
    centos                   version7.1          babd2f913fc9        22 hours ago        262MB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB
    
    # docker save --output centos_version7.1.tar centos:version7.1
    
    # ls -lh
    total 258M
    -rw-------  1 root root 258M Oct 19 21:42 centos_version7.1.tar

     导入镜像

    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        3 hours ago         7.94GB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB
    
    # docker load --input centos_version7.1.tar 
    Loaded image: centos:version7.1
    [root@sht-sgmhadoopnn-01 ~]# docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        3 hours ago         7.94GB
    centos                   version7.1          babd2f913fc9        23 hours ago        262MB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB
  • 相关阅读:
    js流程控制语句
    js流程控制语句
    js流程控制语句
    js流程控制语句
    Nginx入门及如何反向代理解决生产环境跨域问题
    Nginx入门及如何反向代理解决生产环境跨域问题
    Nginx入门及如何反向代理解决生产环境跨域问题
    arcserver开发小结(三)
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11689418.html
一二三 - 开发者的网上家园