Skip to content

Latest commit

Β 

History

History
71 lines (51 loc) Β· 2.17 KB

File metadata and controls

71 lines (51 loc) Β· 2.17 KB

πŸš€ Dockerfile Learning and Practice

Welcome to the Dockerfile Learning and Practice repository! Here, you'll find various Dockerfiles that will help you understand and practice containerization concepts. Whether you're a beginner or an experienced developer, this guide will assist you in mastering Docker commands and best practices. 🐳

πŸ“Œ What You'll Learn

  • How to structure a Dockerfile efficiently.
  • Essential Docker commands and their purpose.
  • Best practices for building lightweight and optimized containers.

πŸ”§ Common Docker Commands

Below is a sample Dockerfile demonstrating key Docker instructions:

# πŸ—οΈ Base Image
# Specifies the lightweight Node.js Alpine base image
FROM node:22-alpine

# πŸ“‚ Set Working Directory
WORKDIR /app

# πŸ”„ Update & Install Dependencies
RUN apt-get update && apt-get install -y curl

# 🌍 Set Environment Variables
ENV NODE_ENV=production

# πŸ“₯ Copy Files from Host to Container
COPY . /app

# πŸš€ Default Command
CMD ["node", "app.js"]

# 🌐 Expose Container Port
EXPOSE 8080

πŸ“š Explanation of Commands

  • FROM node:22-alpine β†’ Defines the base image for the container.
  • WORKDIR /app β†’ Sets the working directory for subsequent instructions.
  • RUN apt-get update && apt-get install -y curl β†’ Installs required dependencies.
  • ENV NODE_ENV=production β†’ Defines environment variables for runtime configurations.
  • COPY . /app β†’ Copies project files from the host to the container.
  • CMD ["node", "app.js"] β†’ Specifies the default command to run when the container starts.
  • EXPOSE 8080 β†’ Declares the port the container will listen on.

πŸš€ Getting Started with Docker

1️⃣ Build the Docker Image

docker build -t my-docker-app .

2️⃣ Run the Container

docker run -p 8080:8080 my-docker-app

3️⃣ Access the Application

Open your browser and go to:

http://localhost:8080

πŸ› οΈ Additional Resources

Happy Coding! πŸš€πŸ³