Using a Dockerfile, Saving and Image, and Using the Interactive Terminal

Cheatsheet and Simple Guide using NGINX

Tech Notes
2 min readApr 20, 2022

Let’s create a Dockerfile. We will use docker image build to build this Dockerfile:

FROM alpine:latest
LABEL maintainer=”Russ McKendrick <russ@mckendrick.io>”
LABEL description=”This example Dockerfile installs NGINX.”
RUN apk add --update nginx && \
rm -rf /var/cache/apk/* && \
mkdir -p /tmp/nginx/
COPY files/nginx.conf /etc/nginx/nginx.conf
COPY files/default.conf /etc/nginx/conf.d/default.conf ADD files/html.tar.gz /usr/share/nginx/
EXPOSE 80/tcp
ENTRYPOINT [“nginx”]
CMD [“-g”, “daemon off;”]

You can use --file to make a custom path to the Dockerfile and --tag to give your image a name:

$ docker image build --file <path_to_Dockerfile> --tag
<REPOSITORY>:<TAG> .Copy

<REPOSITORY> is often your Docker Hub username. For now just use local.

Let’s not use --file and just build inside the same folder as the Dockerfile. This is more common.

$ docker image build --tag local:dockerfile-example .

Check your image and its size:

$ docker image ls

Launch your container:

$ docker container run -d --name dockerfile-example -p 8080:80
local:dockerfile-example

Check your container is running:

$ docker container ls

--

--