1. 程式人生 > >【docker學習二】CentOS7.5+Docker 映象(容器)的使用

【docker學習二】CentOS7.5+Docker 映象(容器)的使用

      承接上篇:https://mp.csdn.net/postedit/82744127

      上文介紹了容器與映象的基本操作,這裡總結下容器的使用。

先在官網找到一個映象:

https://hub.docker.com/r/centos/mysql-57-centos7/
[[email protected] mydc]# docker search centos
FROM ubuntu
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   4722                [OK]                
ansible/centos7-ansible            Ansible on Centos7                              118                                     [OK]
jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86…   99                                      [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   63                                      [OK]
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              45                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      43                                      
centos/mysql-57-centos7            MySQL 5.7 SQL database server                   39                                      
gluster/gluster-centos             Official GlusterFS Image [ CentOS-7 +  Glust…   34                                      [OK]
openshift/base-centos7             A Centos7 derived base image for Source-To-I…   33                                      
centos/python-35-centos7           Platform for building and running Python 3.5…   30                                      
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   29                                      
kinogmt/centos-ssh                 CentOS with SSH                                 22                                      [OK]
openshift/jenkins-2-centos7        A Centos7 based Jenkins v2.x image for use w…   15                                      
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   7                                       
openshift/wildfly-101-centos7      A Centos7 based WildFly v10.1 image for use …   5                                       
openshift/jenkins-1-centos7        DEPRECATED: A Centos7 based Jenkins v1.x ima…   4                                       
darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
pivotaldata/centos                 Base centos, freshened up a little with a Do…   2                                       
pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   2                                       
blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   0                                       
pivotaldata/centos7-build          CentosOS 7 image for GPDB compilation           0                                       
smartentry/centos                  centos with smartentry                          0                                       [OK]
jameseckersall/sonarr-centos       Sonarr on CentOS 7                              0                                       [OK]
pivotaldata/centos7-test           CentosOS 7 image for GPDB testing               0                                       
[
[email protected]
mydc]# docker pull centos/mysql-57-centos7 Using default tag: latest latest: Pulling from centos/mysql-57-centos7 256b176beaff: Pull complete efb19fea0fdb: Pull complete b4570fdc208c: Pull complete 213e4e250552: Pull complete 455c976d8b6f: Pull complete 2d8a583c0d63: Pull complete 997ede30fc40: Pull complete 5cc4480f88a0: Pull complete 2e721eb8f5f6: Pull complete Digest: sha256:c8a8323721c60a49b1792d31a7892731c741d58c238d77b42f0dcf8d7c32c1b4 Status: Downloaded newer image for centos/mysql-57-centos7:latest [
[email protected]
mydc]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos/mysql-57-centos7 latest 34300611d53e 9 days ago 445MB ubuntu latest cd6d8154f1e1 13 days ago 84.1MB [
[email protected]
mydocker]# docker run -d --name mysql_database -e MYSQL_USER=root -e MYSQL_PASSWORD= -e MYSQL_DATABASE=db -p 3306:3306 centos/mysql-57-centos7 f443dd67716c2ffd0570caa35a3aa499c1d1fb65fcc6c6859fa315a51d48777b

檢視本地映象

[[email protected] admin]# docker image list
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
ubuntu_mine               latest              d0ec321b73c6        7 days ago          84.1MB
centos/mysql-57-centos7   latest              34300611d53e        2 weeks ago         445MB
ubuntu                    latest              cd6d8154f1e1        2 weeks ago         84.1MB
mysql/mysql-server        latest              1fdf3806e715        6 weeks ago         309MB

檢視本地容器有哪些

[[email protected] admin]# docker container list
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                          PORTS               NAMES
27c2fb71f4e9        centos/mysql-57-centos7   "container-entrypoin…"   4 minutes ago       Restarting (1) 23 seconds ago                       mysqlofmine
[[email protected] admin]# 

根據映象建立容器

docker container run  
--name=mysqlofmine(container的名字)
--publish=3306:3306  
--volume=/data/mysql/:/var/lib/mysql/  
--restart=always  
--env=MYSQL_ROOT_PASSWORD=123456 
-d centos/mysql-57-centos7(image的名字)