docker學習1--dockerfile

記錄docker學習過程 實踐啓動一個redis serverredis

命令以前 要弄懂docker

dockfileshell

鏡像bash

容器app

三者概念以及三者之間的關係tcp

 

dockerfile格式ide

# Comment 註釋
INSTRUCTION argument

escape

  定義目錄分隔符有關學習

  # escape=` this

  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/ADD test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/
ADD test /absoluteDir/ # adds "test" to /absoluteDir/

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
相關文章
相關標籤/搜索