zoukankan      html  css  js  c++  java
  • docker学习1--dockerfile

    记录docker学习过程 实践启动一个redis server

    命令之前 要弄懂

    dockfile

    镜像

    容器

    三者概念以及三者之间的关系

    dockerfile格式

    # Comment 注释
    INSTRUCTION argument

    escape

      定义目录分隔符有关

      # escape=`

      FROM microsoft/nanoserver

      COPY testfile.txt c:

      RUN dir c:

    ENV

      变量定义

    FROM busybox
    ENV foo /bar
    WORKDIR ${foo}   # WORKDIR /bar
    ADD . $foo       # ADD . /bar
    COPY $foo /quux # COPY $foo /quux


    ARG

    在FROM命令前

    ARG  CODE_VERSION=latest
    FROM base:${CODE_VERSION}
    CMD  /code/run-app
    

    RUN

    • RUN <command> (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
    • RUN ["executable", "param1", "param2"] (exec form)

    CMD

    • CMD ["executable","param1","param2"] (exec form, this is the preferred form)
    • CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
    • CMD command param1 param2 (shell form)

    LABEL

    LABEL multi.label1="value1" multi.label2="value2" other="value3"

    EXPOSE  默认 tcp

    EXPOSE 80/tcp
    EXPOSE 80/udp

    ENV

    ENV myName John Doe
    ENV myDog Rex The Dog
    ENV myCat fluffy

    ADD

    ADD test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/ 
    ADD test /absoluteDir/ # adds "test" to /absoluteDir/

    ADD --chown=55:mygroup files* /somedir/ ADD --chown=bin files* /somedir/ ADD --chown=1 files* /somedir/ ADD --chown=10:11 files* /somedir/

    COPY 同 add

    VOLUME

    WORKDIR

      ENV DIRPATH /path

      WORKDIR $DIRPATH/$DIRNAME

      RUN pwd

    启动redis的样例Dockerfile

    # Use an official redis runtime as a parent image
    FROM redis
    
    # Set the working directory 
    #WORKDIR /wfdata
    
    # Copy the current directory redis config file into the container 
    COPY  ./redis-6379.conf  /usr/local/etc/redis/redis.conf
    
    # Make port local 7378 available to the world outside this container
    EXPOSE 7378
    
    # Run redis-server when the container launches
    CMD redis-server /usr/local/etc/redis/redis.conf & tail -f /dev/null 
    

     

    查看docker容器日志

    docker logs  [OPTIONS]  CONTAINER  [flags]

    例如:

    docker logs a6ad178ebee5
    
  • 相关阅读:
    变量和值的延伸思考
    一念之想--多维数组
    java扫描控制台输入
    java字符转义
    javaee开发工具及环境配置过程
    java数组、泛型、集合在多态中的使用及对比
    flex的Accordion组件头部文本居中显示
    Visual Studio解决方案及项目的配置
    Away3D引擎学习入门笔记
    使用photoshop,把图片背景变成透明
  • 原文地址:https://www.cnblogs.com/kala00k/p/11109605.html
Copyright © 2011-2022 走看看