Docker安装及镜像管理

Docker 安装

[root@kevin ~]# yum install -y docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ircam.fr
 * elrepo: elrepo.reloumirrors.net
 * epel: mirror.kinamo.be
 * extras: mirrors.ircam.fr
 * updates: mirrors.ircam.fr
 * webtatic: uk.repo.webtatic.com
(1/6): mysql57-community/x86_64/primary_db                                                                       | 184 kB  00:00:00     
(2/6): mysql-tools-community/x86_64/primary_db                                                                   |  61 kB  00:00:00     
(3/6): mysql-connectors-community/x86_64/primary_db                                                              |  44 kB  00:00:00     
(4/6): epel/x86_64/primary_db                                                                                    | 6.8 MB  00:00:00     
(5/6): updates/7/x86_64/primary_db                                                                               | 6.5 MB  00:00:00     
(6/6): elrepo/primary_db                                                                                         | 333 kB  00:00:01     
Resolving Dependencies

Installed:
  docker.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos                                                                                       

Dependency Installed:
  PyYAML.x86_64 0:3.10-11.el7                                   atomic-registries.x86_64 1:1.22.1-26.gitb507039.el7.centos              
  audit-libs-python.x86_64 0:2.8.4-4.el7                        checkpolicy.x86_64 0:2.5-8.el7                                          
  container-selinux.noarch 2:2.99-1.el7_6                       container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7                
  containers-common.x86_64 1:0.1.35-2.git404c5bd.el7.centos     device-mapper-event.x86_64 7:1.02.149-10.el7_6.8                        
  device-mapper-event-libs.x86_64 7:1.02.149-10.el7_6.8         device-mapper-persistent-data.x86_64 0:0.7.3-3.el7                      
  docker-client.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos        docker-common.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos                  
  libcgroup.x86_64 0:0.41-20.el7                                libsemanage-python.x86_64 0:2.5-14.el7                                  
  lvm2.x86_64 7:2.02.180-10.el7_6.8                             lvm2-libs.x86_64 7:2.02.180-10.el7_6.8                                  
  oci-register-machine.x86_64 1:0-6.git2b44233.el7              oci-systemd-hook.x86_64 1:0.2.0-1.git05e6923.el7_6                      
  oci-umount.x86_64 2:2.3.4-2.git87f9237.el7                    policycoreutils-python.x86_64 0:2.5-29.el7_6.1                          
  python-IPy.noarch 0:0.75-6.el7                                python-pytoml.noarch 0:0.1.14-1.git7dea353.el7                          
  selinux-policy.noarch 0:3.13.1-229.el7_6.12                   selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.12                    
  setools-libs.x86_64 0:3.3.8-4.el7                             subscription-manager-rhsm-certificates.x86_64 0:1.21.10-3.el7.centos    
  yajl.x86_64 0:2.0.4-4.el7                                    

Dependency Updated:
  audit-libs.x86_64 0:2.8.4-4.el7         device-mapper.x86_64 7:1.02.149-10.el7_6.8  device-mapper-libs.x86_64 7:1.02.149-10.el7_6.8 
  libselinux.x86_64 0:2.5-14.1.el7        libselinux-devel.x86_64 0:2.5-14.1.el7      libselinux-python.x86_64 0:2.5-14.1.el7         
  libselinux-utils.x86_64 0:2.5-14.1.el7  libsemanage.x86_64 0:2.5-14.el7             libsepol.x86_64 0:2.5-10.el7                    
  libsepol-devel.x86_64 0:2.5-10.el7      policycoreutils.x86_64 0:2.5-29.el7_6.1    

Complete!
[root@kevin ~]# systemctl start docker
[root@kevin ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@kevin ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      b2f74b2/1.13.1
 Built:           Wed May  1 14:55:20 2019
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      b2f74b2/1.13.1
 Built:           Wed May  1 14:55:20 2019
 OS/Arch:         linux/amd64
 Experimental:    false
[root@kevin ~]# systemctl start docker.service
 

Docker 镜像管理

# 搜索所有centos的docker镜像

[root@kevin ~]# docker search centos
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/centos                             The official build of CentOS.                   5470      [OK]       
docker.io   docker.io/ansible/centos7-ansible            Ansible on Centos7                              122                  [OK]
docker.io   docker.io/jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.6.1810 x...   110                  [OK]
docker.io   docker.io/consol/centos-xfce-vnc             Centos container with "headless" VNC sessi...   93                   [OK]
docker.io   docker.io/centos/mysql-57-centos7            MySQL 5.7 SQL database server                   59                   
docker.io   docker.io/imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              57                   [OK]
docker.io   docker.io/tutum/centos                       Simple CentOS docker image with SSH access      44                   
docker.io   docker.io/centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relationa...   39                   
docker.io   docker.io/kinogmt/centos-ssh                 CentOS with SSH                                 28                   [OK]
docker.io   docker.io/centos/php-56-centos7              Platform for building and running PHP 5.6 ...   21                   
docker.io   docker.io/pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag nam...   10                   
docker.io   docker.io/guyton/centos6                     From official centos6 container with full ...   9                    [OK]
docker.io   docker.io/drecom/centos-ruby                 centos ruby                                     6                    [OK]
docker.io   docker.io/darksheer/centos                   Base Centos Image -- Updated hourly             3                    [OK]
docker.io   docker.io/mamohr/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                    [OK]
docker.io   docker.io/pivotaldata/centos                 Base centos, freshened up a little with a ...   3                    
docker.io   docker.io/miko2u/centos6                     CentOS6 日本語環境                                   2                    [OK]
docker.io   docker.io/pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated ...   2                    
docker.io   docker.io/pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile...   2                    
docker.io   docker.io/blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                    [OK]
docker.io   docker.io/indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developm...   1                    [OK]
docker.io   docker.io/mcnaughton/centos-base             centos base image                               1                    [OK]
docker.io   docker.io/pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0                    
docker.io   docker.io/pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0                    
docker.io   docker.io/smartentry/centos                  centos with smartentry                          0                    [OK]
 

 #可以使用docker pull命令来从仓库获取所需要的镜像。下面的例子将从Docker Hub仓库下载一个Centos操作系统的镜像。

[root@kevin ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
8ba884070f61: Pull complete 
Digest: sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c
Status: Downloaded newer image for docker.io/centos:latest
# 完成后可以使用该镜像创建一个容器 
[root@kevin ~]# docker run -it centos /bin/bash
[root@c9d43130e231 /]# ls
anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@c9d43130e231 /]# exit
exit

# 镜像的ID唯一标识了镜像,如果ID相同,说明是同一镜像。TAG信息来区分不同发行版本,如果不指定具体标记,默认使用latest标记信息。

# 查看docker镜像
[root@kevin ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              9f38484d220f        4 months ago        202 MB
 

# 如果要移除本地的镜像,可以使用docker rmi命令(在删除镜像之前先用docker rm删除依赖于这个镜像的所有容器)。注意docker rm 命令是移除容器。

[root@kevin ~]# docker rmi 9f38484d220f  # 删除docker镜像

# 如果要导出镜像到本地文件,可以使用docker save命令。

[root@kevin ~]# docker save centos > /opt/centos.tar.gz  # 导出docker镜像至本地
[root@kevin ~]# ls -l /opt/centos.tar.gz 
-rw-r--r--. 1 root root 208301056 July 30 14:48 /opt/centos.tar.gz
[root@kevin ~]# du -sh /opt/centos.tar.gz 
202M	/opt/centos.tar.gz

 # 可以使用docker load从本地文件中导入到本地docker镜像库

[root@kevin ~]# docker load < /opt/centos.tar.gz	# 导入本地镜像到docker镜像库
Loaded image: docker.io/centos:latest
 

 

你可能感兴趣的:(Docker,Docker)