• 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: 绑定指定端口

       

     
  • 相关阅读:
    The C++ Source A Pause to Reflect: Five Lists of Five, Part I The Most Important C++ Books...Ever
    Cg 1.5 Released
    Half Life 2 Source 引擎介绍
    一大清早去飙车
    [旧闻一]NVIDIA招揽前Intel顶级CPU设计师
    [旧闻二]AMD收购ATI
    【翻译】[Effective C++第三版•中文版][第17条]要在单独的语句中使用智能指针来存储由new创建的对象
    Generic:简化异常安全代码
    第29条: 力求使代码做到“异常安全”
    Linux压缩打包命令使用方法
  • 原文地址:https://www.cnblogs.com/maomaochong123/p/8799202.html
Copyright © 2020-2023  润新知