Go Learning
source
go tool tour
Kubernete
Docker
How to build your own docker image
Docker image can be automatically built by using Dockerfile. The whole summary base on the docker documentation.
-
Image building command usage:
docker build <path> -<flag> parameter <file path>
We can use different flags to specialize the image.
flag instruction -f point to a Dockerfile in the file system -t tag an image -
Dockerfile Format:
The file is not case-sensitive. But the convention is to UPPERCASE the comments to distinguish them easily. A Dockerfile must start with
FORM
instruction.Example:
1 2 3 4 5
FROM busybox ENV foo /bar WORKDIR ${foo} # WORKDIR /bar ADD . $foo # ADD . /bar COPY \$foo /quux # COPY $foo /quux
- FROM: initialize a new image and set the Base Image.
- ARG is the only instruction that may precede FROM and can declare the variables.
- RUN:
RUN <command>
: run command in a shell equal to/bin/sh -c
orcmd /S /C
RUN ["executable", "param1", "param2"]
: exec form
- CMD: There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
- The main purpose of a CMD is to provide defaults for an executing container.
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: add metadata to an image. It is a key-value pair.
- MAINTAINER: set the Author field of the generated image.
- example:
LABEL maintainer="SvenDowideit@home.org.au"
- EXPOSE: inform Docker that the container listens on the specified network prots at runtime. - ENV : set the environment vatiable ` ` to the ` `
- example:
- FROM: initialize a new image and set the Base Image.