zoukankan      html  css  js  c++  java
  • docker简记

    首先需要明确上图的几个概念:

    Docker daemon(Docker守护进程)

    Docker daemon是运行在宿主机的后台进程,可以通过Client与之通信;

    Client(Docker客户端)

    Docker客户端用于与用户交互,可以接受用户命令和配置标识,并与Docker daemon通信。docker build等都是Docker的相关命令;

    Images(Docker镜像)

    Docker镜像是一个只读模板,它是一个创建Docker容器的命令集合,通常一个镜像会涵盖其他镜像,并且会有自身的一些定制。它和系统安装ISO程序有点儿像,使用Docker镜像可以创建Docker容器,Docker容器则可以运行我们配置的程序;

    Container(容器)

    容器是镜像的可运行实力,一个镜像可以创建多个容器。

    Registry

    Docker Registry是一个集中存储与分发镜像的服务。一个Docker Registry可包含多个Docker仓库,每个仓库可包含多个镜像标签每个标签对应一个Docker镜像。与Maven仓库类比,Docker Registry可以看做Maven仓库,Docker Repository可以看做某类库,tag可以看做类库版本号,repository+tag可以唯一确定一个镜像

    Docker Registry可分为公有和私有,默认为官方的共有的Docker Hub。


    安装

    1.安装docker

    sudo apt install docker.io

    2.查看docker信息

    sudo docker info

    3.docker的HelloWorld

    sudo docker run hello-world

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    9bb5a5d4561a: Pull complete
    Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/

    Dockerfile常用指令

    FROM

    指定基础镜像

    ENV

    设置环境变量

    ADD src dest

    src为相对当前docker run的路径

    RUN

    可以执行命令,比如RUN rm -rf $DIR_WEBAPP/*   。

    EXPOSE

    指定暴露的端口,指定后在run时添加-P选项,就会暴露该端口,并随机绑定一个宿主机端口,如果需要指定宿主机端口就需要-p hostPort:contanerPort,使用-p并不需要配置EXPOSE。

    CMD

    指定容器启动时执行的命令,以最后一个CMD为准。

    FROM tomcat:9-jre9
    
    ENV TOMCAT_HOME /usr/local/tomcat
    ENV DIR_WEBAPP /usr/local/tomcat/webapps 
    
    ADD web-demo.war $DIR_WEBAPP/web-demo.war 
    
    EXPOSE 80 443
    
    CMD ["catalina.sh", "run"]

    docker常用命令

    docker info

    docker images

    docker build -t repository:tag DockerfilePath

    docker run -it -p 80:80 -v /data:/data -d nginx:latest

    ps: tomcat启动有时会阻塞在产生随机数的地方,需要在catalina.sh中加入JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"

    https://docs.docker.com/engine/docker-overview/#the-docker-platform

  • 相关阅读:
    NPAPI插件开发记录(一) .rc文件 支持Chrome和FireFox
    C语言实现数组快速排序(含对算法的详细解释)
    VBA Address expression
    一起学习winphone7开发系列课程 by 李振
    Performance and memory profiler JefBrains dotTrace tool
    WPF自学教程系列2:如何在xaml文件添加引用?
    for foreach 效率比较
    20130131. CLR C++
    C++ XML编程
    c++ 内存泄露检测
  • 原文地址:https://www.cnblogs.com/holoyong/p/9016059.html
Copyright © 2011-2022 走看看