• docker容器操作


    docker容器创建

    查看当前镜像信息

    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        4 hours ago         7.94GB
    centos                   version7.1          babd2f913fc9        24 hours ago        262MB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB

    创建方式一:docker create

    # docker create --name mysql-container --hostname mysql -it cenots/centos7-mysql57 /bin/bash
    16986e9a0743c1f856a1ef3d02412793577777b4dde331fad9c611757fcb01d0
    
    [root@sht-sgmhadoopnn-01 ~]# docker ps -a
    CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
    16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         23 seconds ago      Created                                 mysql-container

    通过create命令创建的容器处于stop状态,启动该容器

    # docker start mysql-container
    mysql-container
    
    # docker ps -a
    CONTAINER ID        IMAGE                    COMMAND             CREATED              STATUS              PORTS               NAMES
    16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         About a minute ago   Up 3 seconds        3306/tcp            mysql-container

     创建方式二:docker run

    # docker run --name mysql7-container --hostname mysql7 -it cenots/centos7-mysql57 /bin/bash
    
    # docker ps
    CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
    f73cf71d3e8e        cenots/centos7-mysql57   "/bin/bash"         11 seconds ago      Up 9 seconds        3306/tcp            mysql7-container
    16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         4 minutes ago       Up 2 minutes        3306/tcp            mysql-container

     通过run命令创建的容器处于running状态

     进入docker容器

    # docker exec -it mysql-container /bin/bash
    bash-4.4$ hostname
    mysql

     容器的导出和导入

    导出容器

    # docker ps
    CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
    f73cf71d3e8e        cenots/centos7-mysql57   "/bin/bash"         16 hours ago        Up 16 hours         3306/tcp            mysql7-container
    16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         16 hours ago        Up 16 hours         3306/tcp            mysql-container
    
    # docker export --output mysql7-container.tar mysql7-container
    
    # ls -lh
    total 4.6G
    -rw-------  1 root root 4.3G Oct 20 15:29 mysql7-container.tar

     导入容器

    注意:导入容器实际上是导入到镜像,并不是根据导出的tar包产生一个新的容器

    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    cenots/centos7-mysql57   latest              d46f0eee5c07        21 hours ago        7.94GB
    centos                   version7.1          babd2f913fc9        40 hours ago        262MB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB
    
    # docker import mysql7-container.tar centos/mysql:version7
    sha256:b7138378001a6331fc7df1fe07fde0ba42b3a363d3be351a383b04f13082ddbc
    
    
    # docker images
    REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
    centos/mysql             version7            b7138378001a        49 seconds ago      4.57GB
    cenots/centos7-mysql57   latest              d46f0eee5c07        21 hours ago        7.94GB
    centos                   version7.1          babd2f913fc9        41 hours ago        262MB
    centos                   version7            0f3e07c0138f        2 weeks ago         220MB
  • 相关阅读:
    h5网页跳转到app,若未安装app,则跳转app下载页面
    移动端虚拟键盘影响页面布局的问题
    meta标签常用设置
    关于click的多次触发问题(冒泡事件)
    回溯法求解迷宫问题
    记一次MYSQL更新优化
    shell知识点小结
    PHP预定义接口
    【翻译自nikic大神】PHP中原生类型的方法
    找女神要QQ号码
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11706310.html
一二三 - 开发者的网上家园