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

 

posted @ 2019-06-30 14:20  阿飞afei  阅读(226)  评论(0编辑  收藏  举报