This content originally appeared on DEV Community and was authored by Flud
Docker has become a must-have tool for modern software development. Whether youβre building web apps, APIs, or microservices, Docker makes it easier to package, ship, and run applications in a consistent way.
If youβre new to Docker, hereβs a simple beginner-friendly guide to get you started.
What is Docker?
Docker is a platform that lets you run applications inside containers.
A container is like a lightweight, isolated environment that has everything your app needs β code, libraries, dependencies, and settings.
Why Use Docker?
- Consistency β Works the same on your machine, staging, and production.
- Portability β Run anywhere (Linux, Windows, macOS, cloud).
- Isolation β No more “it works on my machine” issues.
- Efficiency β Faster and lighter than full virtual machines.
Key Concepts
- Image β A snapshot/template of your app.
- Container β A running instance of an image.
- Dockerfile β Instructions for building an image.
- Docker Hub β A public registry for Docker images.
Basic Commands
# Check Docker version
docker --version
# Run a container
docker run hello-world
# List running containers
docker ps
# Stop a container
docker stop <container_id>
# Remove a container
docker rm <container_id>
Example: Running Nginx with Docker
docker run -d -p 8080:80 nginx
Visit
http://localhost:8080
and youβll see the Nginx welcome page.
Writing Your First Dockerfile
# Use Node.js base image
FROM node:16
# Set working directory
WORKDIR /app
# Copy project files
COPY . .
# Install dependencies
RUN npm install
# Start the app
CMD ["npm", "start"]
Then build and run:
docker build -t my-app .
docker run -p 3000:3000 my-app
Wrapping Up
Docker helps developers build and deploy apps faster, with fewer headaches. By learning the basics of images, containers, and Dockerfiles, youβre already on your way to mastering containerized development.
Have you started using Docker yet? Whatβs your biggest Docker βaha!β moment? Share in the comments
This content originally appeared on DEV Community and was authored by Flud