🐳

Understanding the Basics of Dockerfile

Aug 3, 2024

Introduction to Dockerfile

What is a Dockerfile?

  • A Dockerfile is a text document that describes how to customize a container.
  • Automates the process of building Docker images (as opposed to manual setup).

Basic Syntax of a Dockerfile

  • Writing a Dockerfile involves understanding some basic commands:

1. FROM

  • The first line must specify the base image.
  • Example: FROM ubuntu

2. ADD

  • Used to add files to the container from the host system.
  • Syntax: ADD <source> <destination>
  • Example: ADD . /var/www/html
  • . means take files from the current directory.

3. RUN

  • Used to execute commands in the container during the build process.
  • Example: RUN apt-get update && apt-get install -y apache2
  • The -y option allows installation without prompts.

4. CMD

  • Specifies commands that should run when the container starts.
  • These commands run only if no arguments are provided during docker run.
  • Example: `CMD