首页 > 其他 > 详细

docker学习1--dockerfile

时间:2019-06-30 15:00:14      阅读:94      评论:0      收藏:0      [点我收藏+]

记录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

 

docker学习1--dockerfile

原文:https://www.cnblogs.com/kala00k/p/11109605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!