Skip to content Dockerfile
- Specify Base Image:
FROM name-of-image
- Define a Working Directory:
WORKDIR /nameofdir
- The name of the directory in which the container will execute commands
- Must be used, CD commands are not persisted across image layers.
- Copy current directory contents into container at
/nameofdir
: ADD . /nameofdir
- Expose a port outside of the container:
EXPOSE portnumber
- Define an environment variable:
ENV NAME variable
- Define Command to Be Run:
RUN <linux-command>
- Add Files to Image:
ADD --CHOWN=<user>:<group> <name-of-file-source> <name-of-file-destination>
- Can also pull from URL
- Can unpack TAR files
- Copy Files to Image:
COPY --CHOWN=<user>:<group> <name-of-file-source> <name-of-file-destination>
- Doesn’t have capabilities of ADD named above.
- Run Command:
ENTRYPOINT: <name-of-command>
CMD: <parameters-of-command>
- Can provide in Exec or Shell Format, former is preferred, uses JSON array.
- Some choose not to use
ENTRYPOINT
and put both command and parameters in CMD
.
- Create Image Command:
docker image build -t <name-of-image>
.- Uses the Dockerfile in the current folder.
- Use
.dockerignore
file to exclude files from being added to image.