Docker in a Day: What I Learned About Containers, Images, and More
A journey into containerization and development optimization.
Introduction
Today I decided to deep-dive into Docker — and it turned out to be one of the most valuable skills I’ve explored as a backend and full stack developer. Docker helps you create, deploy, and run applications in lightweight, portable containers. This blog post captures everything I learned about Docker in a day.
Why Docker?
Docker solves one of the most common problems in development:
"It works on my machine, but not on production."
With Docker, you can ensure consistency across development, testing, and deployment environments. You get isolated containers with all dependencies bundled in — making apps more portable and scalable.
Core Docker Concepts
Docker Image
A Docker image is a read-only template containing your app code, libraries, and environment settings. It’s like a snapshot or blueprint.
Docker Container
A Docker container is a running instance of an image. It’s dynamic, isolated, and runs your app like a lightweight VM — but much faster.
Dockerfile
A text file containing instructions to build a Docker image. Example:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
Docker Compose
Used to manage multi-container apps using a docker-compose.yml file. You can define services,
networks, and volumes in one file.
Volumes
Persistent storage that lives beyond container restarts or removal.
Networks
Allow containers to communicate internally and externally in a secure way.
Docker Commands I Practiced
docker build -t my-app .
docker run -p 3000:3000 my-app
docker ps
docker stop <container_id>
docker exec -it <container_id> sh
docker-compose up
docker-compose down
Interview Questions I Explored
Q: What’s the difference between an image and a container?
A: An image is the static blueprint; a container is the running application.
Q: How would you optimize a Dockerfile?
- Use small base images (e.g.,
alpine) - Leverage multi-stage builds
- Clean up unnecessary files
- Use
.dockerignore - Install only what you need
Optimization Tips I Learned
- Use
node:alpineinstead of full-size images - ? Order instructions for layer caching
- Avoid running as root in production containers
- Use multi-stage builds to separate build-time and runtime dependencies
- Clean up package managers (e.g.,
apk,apt) to keep images lean
What’s Next
- Dockerize a full-stack project (Next.js + Node.js + MongoDB)
- Push my image to Docker Hub
- Learn Kubernetes to scale containerized apps
Conclusion
Docker is more than a buzzword — it's a developer superpower. Whether you're working on microservices, backend APIs, or full-stack apps, Docker can make your workflow faster, cleaner, and production-ready.
If you're new to Docker, I highly recommend diving in. It's one of those tools that pays off almost immediately.