Skip to content

Docker Images

A Docker image is a package that contains the instructions required to build a Docker container. Docker images can be used to create more complex Docker images, and in fact most Docker images are built on top of barebones versions of Ubuntu, Centos, etc.

We can look at what images are available on our local machine by using the following command:

docker images
or
docker image ls

When we want to start a container based off a Docker image, we use:

docker run [image]

The Dockerfile

A Dockerfile is simply a text file that comprises a set of instructions on how to build a Docker image. Example commands that can be used in a Dockerfile are:
- FROM - Creates a layer a base image, like ubuntu
- WORKDIR - Sets the working directory for any RUN, CMD, ...
- PULL - Adds files from your Docker repository
- COPY - Copy files from the host machine to the container
- RUN - Builds your container
- CMD - Specifies what command to run within the container

To use a Dockerfile to build a Docker image, we can run:

docker build [image]

Example Dockerfile

FROM node:12-alpine
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production
COPY . .
CMD ["node", "src/index.js"]