What is a Dockerfile?
A text file with instructions to build a Docker image.
Basic Structure
dockerfile
1# Base image
2FROM ruby:3.2
3
4# Set working directory
5WORKDIR /app
6
7# Copy files
8COPY . .
9
10# Install dependencies
11RUN bundle install
12
13# Expose port
14EXPOSE 3000
15
16# Start command
17CMD ["rails", "server", "-b", "0.0.0.0"]Common Instructions
| Instruction | Description |
|---|---|
FROM | Base image |
WORKDIR | Set working directory |
COPY | Copy files into image |
ADD | Copy with extras (URLs, tar) |
RUN | Execute command |
ENV | Set environment variable |
EXPOSE | Document port |
CMD | Default command |
ENTRYPOINT | Fixed command |
Building
bash
1docker build -t myapp .
2docker build -t myapp:v1.0 -f Dockerfile.prod .Build Context
The . in docker build -t myapp . is the build context - files available during build.
