docker learning 1 - dockerfile

Record docker learning practices start a redis server

Before the command to understand

dockfile

Mirroring

container

The relationship between the three concepts as well as three

 

dockerfile format

# Comment 注释
INSTRUCTION argument

escape

  The definition of the relevant directory separator

  # escape=`

  FROM microsoft/nanoserver

  COPY testfile.txt c:\

  RUN dir c:\

 

ENV

  Variable definitions

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


ARG

Before FROM command

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 default 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

 

 

Start redis sample 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 

 

 

 

 

 

 

 

View docker container logs

docker logs  [OPTIONS]  CONTAINER  [flags]

E.g:

docker logs a6ad178ebee5

 

Guess you like

Origin www.cnblogs.com/kala00k/p/11109605.html