Building Custom Images
A Dockerfile is a text file with instructions for building a Docker image. Each instruction creates a new layer in the image.
Simple Dockerfile
# Use Node.js 20 as the base image
FROM node:20
# Set working directory inside the container
WORKDIR /app
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install
# Copy the rest of your application code
COPY . .
# Expose port 3000
EXPOSE 3000
# Start the application
CMD ["node", "server.js"]
Dockerfile Instructions
Building the Image
5d17c0f5e3c2
Step 2/6 : WORKDIR /app
---> Using cache
---> 7e1c8d3f9a4b
...
Successfully built 9f2e1d4c8a7b
Successfully tagged myapp:1.0