Docker Basics for DevOps

Day 5 of #30DaysOfDevOps — Docker Basics Docker is one of the most important tools in DevOps. It ensures your app runs the same way on your laptop, in staging, and in production. No more "it works on my machine." 1. Why Docker? Docker packages your app and everything it needs into a single container that runs consistently anywhere. Containers vs VMs: - VMs include a full OS — heavy, slow to start - Containers share the host OS kernel — lightweight, start in seconds 2. Core Concepts Image — read-only template with your app and dependencies Container — a running instance of an image Dockerfile — instructions to build an image Docker Hub — public registry to store and share images 3. Essential Commands Run a container: docker run -d -p 8080:80 nginx List running containers: docker ps Stop and remove: docker stop 3f2a1b docker rm 3f2a1b Shell into a running container: docker exec -it 3f2a1b bash 4. Writing a Dockerfile FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 4000 CMD ["node", "server.js"] Build and run: docker build -t my-app:v1.0 . docker run -d -p 4000:4000 my-app:v1.0 5. Push to Docker Hub docker tag my-app:v1.0 yourname/my-app:v1.0 docker login docker push yourname/my-app:v1.0 6. Optimization Tips Use alpine images — 5x smaller than full OS images Add .dockerignore to exclude node_modules and .git Copy package files before source code to maximize layer caching 7. Challenges for Today 1. Install Docker and verify with: docker run hello-world 2. Run an nginx container on port 8080 and open it in your browser. 3. Write a Dockerfile for a Python or Node.js app and build it. 4. Tag your image and push it to Docker Hub. 5. Shell into a running container and explore the filesystem. 6. Add a .dockerignore and observe the build context size difference. Drop your Docker Hub image link in the comments. #DevOps #Docker #Containers #Dockerfile #30DaysOfDevOps #LearningInPublic #DevOpsEngineer #CloudComputing

To view or add a comment, sign in

Explore content categories