• docker的应用


    [root@yz6205 ~]# docker images
    INFO[0063] GET /v1.19/images/json
    REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
    ubuntu latest 7bd023c8937d 41 hours ago 122 MB
    ubuntu 14.04 0e7d4a488bcc 41 hours ago 187.9 MB
    centos latest db0f5936b391 11 days ago 196.7 MB
    [root@yz6205 ~]# docker run -t -i ubuntu /bin/bash
    INFO[0127] POST /v1.19/containers/create
    INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/attach?stderr=1&stdin=1&stdout=1&stream=1
    INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/start
    INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/resize?h=26&w=121
    root@5b1280645766:/#

    创建镜像
    1,基于已有镜像的容器创建
    root@68dea79aa079:~# cat /etc/issue
    Ubuntu 16.04 LTS l

    [root@yz6205 ~]# docker commit -m "Add a new file" -a "docker newbee" 68dea79aa079 test
    933b24d02ecfacb81ad0afa1c0d85d651eeea8dba3c6e2ec0e3859fff92eb9a2
    [root@yz6205 ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
    test latest 933b24d02ecf About a minute ago 122 MB
    ubuntu latest 7bd023c8937d 41 hours ago 122 MB

    存入镜像
    [root@yz6205 ~]# docker save -o ubuntu_14.04.tar 933b24d02ecf

    载入镜像
    [root@yz6205 ~]# docker load --input ubuntu_14.04.tar
    或者:
    [root@yz6205 ~]# docker load < ubuntu_14.04.tar


    查看log信息
    [root@yz6205 ~]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    074b5ad4936f ubuntu "/bin/bash" About a minute ago Exited (0) 44 seconds ago admiring_mccarthy
    [root@yz6205 ~]# docker logs 074
    root@074b5ad4936f:/# pwd
    /
    root@074b5ad4936f:/# ls
    bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
    root@074b5ad4936f:/# ps
    PID TTY TIME CMD
    1 ? 00:00:00 bash
    13 ? 00:00:00 ps
    root@074b5ad4936f:/# exit
    exit


    终止容器
    [root@yz6205 ~]# docker stop 074
    074
    [root@yz6205 ~]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    074b5ad4936f ubuntu "/bin/bash" 5 minutes ago Exited (0) 4 minutes ago admiring_mccarthy
    [root@yz6205 ~]# docker start 074
    074
    [root@yz6205 ~]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    074b5ad4936f ubuntu "/bin/bash" 5 minutes ago Up 1 seconds

    查看处于终止状态下的容器的ID信息
    [root@yz6205 ~]# docker ps -a -q
    074b5ad4936f
    67156b0cfc7c
    68dea79aa079
    5b1280645766
    d65d3ac7c374
    10bbf0542e24
    33e3c46add98
    dac0735f6767
    31472d1eefcb


    重启docker
    [root@yz6205 ~]# docker restart 074
    074
    [root@yz6205 ~]# docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    074b5ad4936f ubuntu "/bin/bash" 8 minutes ago Up 9 seconds admiring_mccarthy

    -d参数,容器启动后讲进入后台
    [root@yz6205 ~]# docker run -idt centos
    193840bce6de1e26e1263239c7a3fee9c9bb2c8e9b0f43fe0ba4084676e37bfd

    [root@yz6205 ~]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    193840bce6de centos "/bin/bash" 48 seconds ago Up 36 seconds sad_albattani

    可使docket attach 、docket exec 、nsenter等工具查看
    [root@yz6205 ~]# docker attach sad_albattani
    [root@193840bce6de /]#

    [root@yz6205 ~]# docker exec -ti 193840bce6de /bin/bash
    [root@193840bce6de /]#


    导出容器
    [root@yz6205 soft]# docker export 193 > 193840bce6de_centos_tar
    [root@yz6205 soft]# ls
    193840bce6de_centos_tar

    docker登陆注册
    [root@yz6205 soft]# docker login
    Username: yongsan
    Password: 123qwe
    Email: yongsan@staff.sina.com.cn
    WARNING: login credentials saved in /root/.docker/config.json
    Account created. Please use the confirmation link we sent to your e-mail to activate it.

    使用registry创建私有仓库
    [root@yz6205 soft]# docker run -d -p 5000:5000 registry
    Unable to find image 'registry:latest' locally
    latest: Pulling from registry
    f15ce52fc004: Pull complete
    c4fae638e7ce: Pull complete
    a4c5be5b6e59: Pull complete
    8693db7e8a00: Pull complete
    c75fbf48538e: Downloading [=======================================> ] 70.28 MB/89.2 MB
    87c008f1a79b: Download complete
    5a7b60cbc471: Download complete
    81569492134a: Download complete
    0aed6b236dec: Download complete

    管理私有仓库
    docker tag 命令给镜像标记重命名
    [root@yz6205 soft]# docker tag ubuntu:14.04 10.39.6.205:5000/test
    [root@yz6205 soft]# docker images
    REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
    test centos 2a3044c7fb64 58 minutes ago 196.7 MB
    test 193840bce6de a753d5365391 59 minutes ago 196.7 MB
    ubuntu latest 7bd023c8937d 43 hours ago 122 MB
    10.39.6.205:5000/test latest 0e7d4a488bcc 43 hours ago 187.9 MB


    下面使用training/webapp 镜像创建一个web容器,并创建一个数据卷挂载到容器的/data0/soft目录
    [root@yz6205 soft]# docker run -d --name web -v /data0/soft training/webapp python app.py
    Unable to find image 'training/webapp:latest' locally
    latest: Pulling from training/webapp
    e9e06b06e14c: Pull complete
    a82efea989f9: Pull complete
    37bea4ee0c81: Pull complete
    07f8e8c5e660: Pull complete
    23f0158a1fbe: Pull complete
    0a4852b23749: Pull complete
    7d0ff9745632: Pull complete
    99b0d955e85d: Pull complete
    33e109f2ff13: Pull complete
    cc06fd877d54: Pull complete
    b1ae241d644a: Pull complete
    b37deb56df95: Pull complete
    02a8815912ca: Already exists
    Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11d
    Status: Downloaded newer image for training/webapp:latest
    1c413b58919b2728cabede1639d1a12fa72fe74ab3cfee56a76fdb6ae1bc416a

    -p/P指定端口
    [root@yz6205 soft]# docker run -d -P training/webapp python app.py
    48beffc1c93351262ef03c9f65e7f4364e5e6414f3e40bd5db256771f0110102

    [root@yz6205 dir]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    48beffc1c933 training/webapp "python app.py" 44 seconds ago Up 27 seconds 0.0.0.0:32768->5000/tcp clever_goodall

    访问宿主机的32768端口即可访问容器内web应用提供的页面了
    [root@yz6205 soft]# curl http://10.39.6.205:32768
    Hello world![root@yz6205 soft]#

    [root@yz6205 dir]# docker logs -f clever_goodall
    * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
    * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
    10.39.6.205 - - [29/May/2016 11:23:47] "GET / HTTP/1.1" 200 -
    10.212.60.113 - - [29/May/2016 11:24:10] "GET / HTTP/1.1" 200 -
    10.212.60.113 - - [29/May/2016 11:24:10] "GET /favicon.ico HTTP/1.1" 404 -

    -p可以将本地的5000端口映射到容器的5000端口
    [root@yz6205 soft]# docker run -d -p 5000:5000 training/webapp python app.py
    b801e4036691e60b0b671883e4b06b8414aef23e495ed2b8cbe7f841c7a8746b

    [root@yz6205 soft]# docker ps -l
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    b801e4036691 training/webapp "python app.py" 56 seconds ago Up 35 seconds 0.0.0.0:5000->5000/tcp prickly_yonath

  • 相关阅读:
    centos7安装Oracle12c
    Spring框架学习总结(上)
    如何教会女友递归算法?
    别翻了,这篇文章就是要让你入门java多线程!
    【从今天开始好好学数据结构04】程序员你心中就没点“树”吗?
    【从今天开始好好学数据结构03】链表
    【从今天开始好好学数据结构02】栈与队列
    别翻了,这篇文章绝对让你深刻理解java类的加载以及ClassLoader源码分析【JVM篇二】
    深入理解java继承从“我爸是李刚”讲起
    深入理解java多态没有烤山药的存在,java就不香了吗?
  • 原文地址:https://www.cnblogs.com/liyongsan/p/5539732.html
Copyright © 2020-2023  润新知