What does the stuff inside a docker file mean?

A walk-through of the common attributes within a docker file

Just a quick refresh on the elements of a sample docker file:

FROM ubuntu

LABEL maintainer="Mike <example@domain.blah>"

USER root

COPY ./foo.bash /

RUN apt -y update
RUN apt -y install foo foo2
RUN chmod 755 /foo.bash

USER nobody

ENTRYPOINT [ "/foo.bash" ]
  • FROM ubuntu tells Docker which existing Docker image to base your Docker image off of. By default, Docker tries to get the image from Docker hub if it's not already on the local machine.
  • LABEL lets us add some additional metadata to the image. In this case, we're noting the maintainer of the image.
  • USER tells docker which user to use for any docker file commands underneath it. In this case, we're specifying the root user (example only).
  • COPY copies files from a directory provided to the Docker build command to the container image.
  • RUN statements are commands that customize our image. This is a great place to install additional software or configure files needed by your application. In the example above, we're requesting foo and foo2 to be installed (with the expectation that they're needed in order for foo.bash to run.
  • ENTRYPOINT tells docker what command containers created from this image should run.

Check out the latest documentation on the dockerfile reference