Search

Search IconIcon to open search

dockerfile

Last updatedUpdated: by Simon Späti · CreatedCreated: · 2 min read

A dockerfile can be used to build an image and then run as a container on docker terms or as a pod in Kubernetes.

A Dockerfile is a text file that contains a series of instructions on how to build a Docker image. It’s like a recipe that tells Docker how to set up an environment for your application. Here’s a breakdown of what it typically includes:

  1. Base Image: Specifies the starting point, usually an existing image like ubuntu or node.
  2. Commands: Instructions to install software, copy files, set environment variables, and configure settings.
  3. Entry Point: Defines the command to run when the container starts.

# Arguments supported in a Dockerfile

The Dockerfile supports the following instructions:

Instruction Description
ADD Add local or remote files and directories.
ARG Use build-time variables.
CMD Specify default commands.
COPY Copy files and directories.
ENTRYPOINT Specify default executable.
ENV Set environment variables.
EXPOSE Describe which ports your application is listening on.
FROM Create a new build stage from a base image.
HEALTHCHECK Check a container’s health on startup.
LABEL Add metadata to an image.
MAINTAINER Specify the author of an image.
ONBUILD Specify instructions for when the image is used in a build.
RUN Execute build commands.
SHELL Set the default shell of an image.
STOPSIGNAL Specify the system call signal for exiting a container.
USER Set user and group ID.
VOLUME Create volume mounts.
WORKDIR Change working directory.

More on the Docker Docs on Dockerfile reference.

# Simple Example with nginx

Example with nginx.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Use the official NGINX image from Docker Hub
FROM nginx:latest

# Copy your custom NGINX configuration file (if you have one)
# COPY nginx.conf /etc/nginx/nginx.conf

# Copy static website files to the appropriate directory
# COPY . /usr/share/nginx/html

# Expose the port NGINX listens on
EXPOSE 80

# Docker Commands

Docker Commands.

# Run from a local DockerFile

Step-by-Step Process

  1. Build an image from your Dockerfile:
1
docker build -t test .
  1. Run a container from that image:
1
bashdocker run -d --name my-container test

or in one go:

1
docker build -t test . && docker run -d --name my-container test

Simple Docker Setup

Check my quick GitHub repo setup that can be cloned and used: simple-docker-setup: Local docker setup to test repository or code from a fresh state for data engineering.

See also more on Run Docker Images and Containers in interactice (-it) mode or Kubernetes - Course (Basics).


Origin: