CentOS Docker 基本操作

 1,  CentOS Docker 安装

  使用 yum 安装(CentOS 7下)

  Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

  通过 uname -r 命令查看你当前的内核版本

  [root@iZ28oyrbb21Z ~]# uname -r
  3.10.0-327.22.2.el7.x86_64

  安装 Docker

  Docker 软件包和依赖包已经包含在默认的 CentOS-Extras 软件源里,安装命令如下:

  [root@runoob ~]# yum -y install docker

2,  CentOS Docker 基本命令

  [root@iZ28oyrbb21Z ~]# /bin/systemctl stop  docker.service            #停止Docker

  [root@iZ28oyrbb21Z ~]# /bin/systemctl start  docker.service       #启动Docker

  [root@iZ28oyrbb21Z ~]# docker version              #查看Docker版本

  [root@iZ28oyrbb21Z ~]# docker                   # 查看所有可用的Docker命令

  [root@iZ28oyrbb21Z ~]# docker stats --help             # 查看具体一个命令详细的使用方法

  [root@iZ28oyrbb21Z ~]# docker ps                #查看我们正在运行的容器

  

3,  CentOS Docker 镜像基本使用

  [root@iZ28oyrbb21Z ~]# docker search httpd     # 我们可以从 Docker Hub 网站来搜索镜像

  [root@iZ28oyrbb21Z ~]# docker pull httpd          #使用httpd 官方版本的镜像,使用命令 docker pull 来下载镜像。

  [root@iZ28oyrbb21Z ~]# docker images        #列出本地主机上的镜像。

  

  各个选项说明:

    •   REPOSITORY:表示镜像的仓库源

    •   TAG:镜像的标签

    •   IMAGE ID:镜像ID

    •   CREATED:镜像创建时间

    •   SIZE:镜像大小

   

  同一仓库源可以有多个 TAG,代表这个仓库源的不同个版本,如ubuntu仓库源里,有15.10、14.04等多个不同的版本,我们使用 REPOSITORY:TAG 来定义不同的镜像。

  所以,我们如果要使用版本为15.10的ubuntu系统镜像来运行容器时,命令如下:

  [root@iZ28oyrbb21Z ~]# docker run -t -i ubuntu:15.10 /bin/bash

  

  如果你不指定一个镜像的版本标签,例如你只使用 ubuntu,docker 将默认使用 ubuntu:latest 镜像。

     

4,  CentOS Docker 运行一个web应用

  [root@iZ28oyrbb21Z ~]# docker port ab86556a5c2c    #查看到容器(指定ID或者名字)的端口映射

  [root@iZ28oyrbb21Z ~]# docker logs -f ab86556a5c2c    # 输出容器内部的标准输出。

  [root@iZ28oyrbb21Z ~]# docker top ab86556a5c2c    # 查看容器内部的进程

  [root@iZ28oyrbb21Z ~]# docker restart ab86556a5c2c    #使用命令 docker restart 来重启指定的容器(指定ID或者名称)

  [root@iZ28oyrbb21Z ~]# docker rm ab86556a5c2c      #删除指定的容器

   [root@iZ28oyrbb21Z ~]# docker run -d -p 5000:5000 training/webapp python app.py

  

  

  参数说明:

    •   -d: 让容器在后台运行。

    •   -p: 绑定指定端口

   

 
原文地址:https://www.cnblogs.com/maomaochong123/p/8799202.html