Skip to main content

Working with Docker Images

Building Images with Dockerfile

0:00
LearnStep 1/4

Introduction to Dockerfile

What is a Dockerfile?

A Dockerfile is a text file containing instructions for building a Docker image. It automates the image creation process.

Basic Structure

dockerfile

Common Instructions

  • FROM: Specifies the base image
  • RUN: Executes commands during build
  • COPY: Copies files from host to image
  • ADD: Like COPY but with extra features
  • WORKDIR: Sets working directory
  • ENV: Sets environment variables
  • EXPOSE: Documents which ports to expose
  • CMD: Default command to run
  • ENTRYPOINT: Configures container as executable

Simple Example

dockerfile

Building the Image

bash