If you need a highly specific environment, the best place to "download" examples is . Search for a language (e.g., "PostgreSQL" or "Go"). Look for the "Official Image" tag.
Think of this as cd . It sets the folder where all following commands happen.
Put the things that change least (like installing libraries) at the top, and things that change most (like your source code) at the bottom. This makes building faster. Where to Find More Examples? download dockerfile example
Use COPY for local files. ADD is rarely used unless you need to extract a ZIP or download a URL directly.
This is the default command that runs only when the container starts. Best Practices for Your Dockerfiles If you need a highly specific environment, the
Just like .gitignore , this prevents bulky files (like node_modules or .git ) from being copied into your image.
Click on the tab to see the Dockerfile source code for that specific version. yml file to go along with one of these examples? Think of this as cd
# 1. Use the official Node image FROM node:18-alpine # 2. Create app directory WORKDIR /usr/src/app # 3. Install app dependencies COPY package*.json ./ RUN npm install # 4. Bundle app source COPY . . # 5. Expose the port your app runs on EXPOSE 3000 # 6. Start the application CMD ["npm", "start"] Use code with caution. 3. Static Website (Nginx) Dockerfile Example