Skip to content

Instantly share code, notes, and snippets.

@dangerwolf
Created December 9, 2016 08:34
Show Gist options
  • Select an option

  • Save dangerwolf/f4a99a4820d15c6504ae72d787cbf939 to your computer and use it in GitHub Desktop.

Select an option

Save dangerwolf/f4a99a4820d15c6504ae72d787cbf939 to your computer and use it in GitHub Desktop.

Revisions

  1. dangerwolf created this gist Dec 9, 2016.
    151 changes: 151 additions & 0 deletions Docker.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,151 @@


    # Docker

    [TOC]

    ## 避不开的对比:Docker VS 虚拟机

    好像很多人都在意或者愿意去讨论对比Docker和虚拟机之间的优劣或者说是优缺点。

    上网查了一些资料,大同小异。为节省大家上网的检所查询的时间,我就总结以下网上的若干结论。

    | | Docker | 虚拟机 |
    | ---- | ------------- | ------------- |
    | 性能 | 高,接近物理机 | 低,接近物理机的50% |
    | 安全性 | 低,暂时没有权限管理 | 高,可以完美隔离 |
    | 占用资源 | 低,资源共享或使用物理资源 | 高,用物理资源虚拟硬件资源 |
    | 启动速度 |||
    | 配置 | 轻便 | 相对繁琐 |
    | 体积 | 轻巧 | 巨大 |



    ## Docker的适用场景

    Docker其实可以看做是PaaS的一种,故适用于PaaS的场景都可以使用Docker。



    # 安装

    ## MacOS

    ~~~
    https://docs.docker.com/docker-for-mac/
    ~~~



    ## Windows

    ~~~
    https://docs.docker.com/docker-for-windows/
    ~~~





    # 常用命令

    ## 显示所有image

    docker image ls
    可能显示类似下面的信息:

    REPOSITORY TAG IMAGE ID CREATED SIZE
    oraclelinux latest 7f518b709a70 2 weeks ago 225 MB
    dangerwolf/ubuntu_wolf latest e5a07645890c 4 weeks ago 737 MB
    <none> <none> 39d4c5e3d690 4 weeks ago 709 MB
    <none> <none> 352bbe0a292f 4 weeks ago 709 MB
    <none> <none> 80b2042a2e70 4 weeks ago 709 MB
    <none> <none> 924c43bcde51 4 weeks ago 709 MB
    tomcat latest 7b6daea9936c 6 weeks ago 355 MB
    mysql latest cf725f136fd2 6 weeks ago 383 MB
    mongo latest 092cc6fb995c 6 weeks ago 342 MB
    ubuntu latest f753707788c5 7 weeks ago 127 MB
    wnameless/oracle-xe-11g latest b4d052e20bda 5 months ago 2.23 GB
    hub.c.163.com/public/ubuntu 16.04 70b70c987e8f 10 months ago 224 MB
    ## 删除image
    通过`rmi`命令执行的删除命令属于物理删除。
    如显示如下信息则表示删除成功。

    Deleted: sha256:49da04ba733abe7c14fe8b87ac58f2933bda9dc8edc3c1226e4b6ffce5a0f2ca
    ### 通过id进行删除
    docker rmi 49da04ba733a
    后面的参数为通过`docekr image ls`查出的`IMAGE ID`

    ### 通过名称进行删除
    docker rmi oraclelinux
    后面的参数为通过`docekr image ls`查出的`REPOSITORY`

    ## 下载image

    docker pull iwakoshi/eclipse

    可能会显示如下信息:

    Using default tag: latest
    latest: Pulling from iwakoshi/eclipse
    df22f9f3e4ec: Pull complete
    a3ed95caeb02: Pull complete
    635788c924ce: Pull complete
    b7d066d63351: Extracting [> ] 5.571 MB/387.4 MB
    6a9ca9be965a: Download complete
    dae76836d73b: Download complete
    e9527d9fa00d: Download complete

    ## 查看Container

    docker ps
    其显示结果可能如下:

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    135ef118c2b9 showdoc_wolf:latest "apache2-foreground" 11 minutes ago Up 11 minutes 0.0.0.0:4999->80/tcp showdoc_wolf

    ## 登录docker.io
    docker login
    其显示结果可能如下:

    Login with your Docker ID to push and pull images from Docker Hub. If you do not have a Docker ID, head over to https://hub.docker.com to create one.
    Username (dangerwolf): dangerwolf
    Password:
    Login Succeeded

    依次输入用户名和密码后(每次输入均以回车键确认)可完成登录。



    ## 给image打tag

    ~~~
    docker tag 135ef118c2b9 dangerwolf/showdoc:latest
    ~~~



    ```
    docker tag [imageId] [imageName]
    ```

    tag后面的参数依次为镜像ID、用户名或者组织名、仓库名和版本。

    ## 提交image

    ~~~
    docker push dangerwolf/showdoc
    ~~~



    # 常用的管理工具

    ## Kitematic

    官方推荐的一款管理工具

    ~~~
    https://kitematic.com/
    ~~~