Dockerfile
Defines the container environment.
Commands
FROM
A base image
a valid Dockerfile must start with a
FROMinstruction
FROM ubuntuUSER
Set the user (and possibly the group)
USER usernameUSER username:groupUSER UIDUSER UID:GIDWORKDIR
Sets the working directory. This will be used by any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD commands.
Multiple WORKDIRs can be specified; relative WORKDIRs will be on the previous WORKDIR path.
WORKDIR /testWORKDIT ing # /test/ingENV
Set an environment variable
ENV key value # one variableENV key=value another=value # multiple variables, requires equals signADD
Copy files, directories, and URLs from source to destination.
If the source is a recognized archive format, ADD will unpack it.
ADD source destination # UID & GID = 0ADD --chown=UID:GID source destinationADD --chown=UID source destination # GID = UIDSource interpreted relative to build's source context.
Destination is either absolute or relative to the WORKDIR
If --chown is not provided, files/directories created with UID & GID of 0.
COPY
Copy files/directories from source to destination. COPY is like ADD, but doesn't support URLs and does not unpack archives.
COPY source destinationCOPY ["source with spaces", "destination location"]COPY --chown=user:group source destinationCMD
Run a command, primarily used for provide defaults for executing container.
Only one CMD is allowed per Dockerfile. If there are multiple, the last one will be used.
CMD ["executable", "param", "another"]CMD command param anotherRUN
Run a command and create a new image. Use case: install a package on top of the OS.
The command can either be provided in shell form or exec form.
RUN command # shell formRUN ["sequence", "of", "values"] # exec formARG
A build-time variable, with optional default value.
ARG nameARG other=defaultDocker comes with some built-in args.
LABEL
Used for adding metadata to an image with key value pairs.
LABEL one="two"LABEL three="four" five="six"LABEL seven="eight" \ nine="ten" \ "eleven twelve"="thirteen"An image's labels can be viewed using docker inspect.
EXPOSE
Tell docker to listen to specified port. TCP or UDP (TCP is default if not specified)
EXPOSE 80/tcpEXPOSE 123 # tcpEXPOSE 456/udpThese can be overriden at runtime with the -p flag.
docker run -p 80:80/tcpENTRYPOINT
configure a container that will run as an executable
ENTRYPOINT ["executable", "one", "two"] # exec formENTRYPOINT command one two # shell formVOLUME
Create a mount point