0% found this document useful (0 votes)
4 views3 pages

Dockerfile Guide

The document is a comprehensive guide to Dockerfile commands, detailing their purpose and usage with examples. Key commands include FROM for base images, WORKDIR for setting the working directory, and CMD for defining the default command on container start. Additional features like ARG for build-time variables and VOLUME for persistent storage are also explained.

Uploaded by

musheeran165
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Dockerfile Guide

The document is a comprehensive guide to Dockerfile commands, detailing their purpose and usage with examples. Key commands include FROM for base images, WORKDIR for setting the working directory, and CMD for defining the default command on container start. Additional features like ARG for build-time variables and VOLUME for persistent storage are also explained.

Uploaded by

musheeran165
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DOCKERFILE COMPLETE GUIDE

1. FROM
Base image for container.
Example: FROM node:20-alpine
Use: Provides OS + runtime.

2. WORKDIR
Working directory inside container.
Example: WORKDIR /app
Use: All commands run here.

3. COPY
Copy files from host to container.
Example: COPY . .
Use: Moves project files.

4. ADD
Advanced copy (auto unzip, URLs).
Example: ADD [Link] /app
Use: Special copy cases.

5. RUN
Executes command at build time.
Example: RUN npm install
Use: Install dependencies.

6. CMD
Default command when container starts.
Example: CMD ["npm","start"]
Use: Start app.

7. ENTRYPOINT
Fixed startup command.
Example: ENTRYPOINT ["node","[Link]"]
Use: Force command execution.

8. EXPOSE
Documents app port.
Example: EXPOSE 3000
Use: Port info.

9. ENV
Runtime environment variable.
Example: ENV NODE_ENV=production
Use: Runtime config.
10. ARG
Build-time variable.
Example: ARG VERSION=1.0
Use: Build control.

11. LABEL
Metadata.
Example: LABEL author="FUG"
Use: Info tagging.

12. VOLUME
Persistent storage.
Example: VOLUME /data
Use: Save data outside container.

13. USER
Run as user.
Example: USER node
Use: Security.

14. SHELL
Change shell.
Example: SHELL ["/bin/bash","-c"]
Use: Better scripting.

15. STOPSIGNAL
Graceful stop signal.
Example: STOPSIGNAL SIGTERM
Use: Clean shutdown.

16. HEALTHCHECK
Container health monitor.
Example: HEALTHCHECK CMD curl --fail [Link] || exit 1
Use: App health check.

LOGIC (IF/ELSE)
Dockerfile has no logic. Use shell.

Example:
ARG MODE=prod
RUN if [ "$MODE" = "prod" ]; then echo "PROD"; else echo "DEV"; fi

ARG (DETAILED)
Build-time only variable. Not accessible at runtime.
Used for versions, build modes, feature flags.

VOLUME (DETAILED)
Persistent external storage.
Data survives container deletion.
Used for DBs, uploads, logs.

Example:
-v pg_data:/var/lib/postgresql/data

You might also like