Learn How To Create A Dockerfile in 203 Seconds

By Lukas Aichbauer and Ivan Popovic | February 29, 2024 | 3 min watch time

Description

Learn in 162 seconds why you need Docker, what it is all about, and how the three core components work together.

Learning outcomes

  • What is a Dockerfile?
  • How do I create my first Dockerfile?
  • What Commands do I need?
  • How do the commands work together?
  • How does the cache function work?
  • How do layers work?

Commands You Will Learn

FROM <base-image> – Set the base image for your Dockerfile (e.g. FROM node:18-alpine). You can search for them on Docker Hub

COPY <path-on-host-file-system> <path-in-image-file-system> – Copy files and directories into the final Docker image (e.g. COPY ./package* .).

RUN <command> – Run a command inside your Docker image, but on build time (e.g. RUN npm install)

EXPOSE <port> – Glorified comment telling a developer which ports are used in this Docker image (e.g. EXPOSE 3000)

CMD [<command>, <option>, <...>] – This is the command that will be executed when the container is started (e.g. CMD ["node", "./build/server.js"])