dockerfile
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:
- Base Image: Specifies the starting point, usually an existing image like
ubuntuornode. - Commands: Instructions to install software, copy files, set environment variables, and configure settings.
- 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.
|
|
# Docker Commands
# Run from a local DockerFile
Step-by-Step Process
- Build an image from your Dockerfile:
|
|
- Run a container from that image:
|
|
or in one go:
|
|
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: