Easy Docker Setup for Applications

Docker is not that hard to setup once you know the drilln shure it can be scary! but trust me its not that hard 🙂

Using Docker while programming is often beneficial, but whether you should use it depends on your specific needs and use case, I’ll give some pros and cons at the end of the pah.

When to use Docker containers

Consistent Development Environment
Docker ensures that your application runs the same way on all machines, regardless of operating system or system configuration. This eliminates the “it works on my machine” problem.

Isolated Dependencies
Each Docker container has its own isolated environment. This means you can work on multiple projects with different dependencies (e.g., Python 3.10 for one project and 3.8 for another) without conflicts.

Simplified Onboarding
If you’re part of a team, new developers can quickly set up the project by running a Docker container instead of installing and configuring dependencies manually.

Microservices Development
Docker is ideal for developing microservices, as it allows you to run different parts of your application in separate containers.

Reproducible Builds
Docker enables you to test in an environment similar to production, reducing the likelihood of deployment issues.

Cross-Platform Compatibility
Applications packaged with Docker run consistently across different platforms (Windows, macOS, Linux).one project and 3.8 for another) without conflicts.

You dont’t or might not need Docker

Simple Projects
For small or straightforward projects without complex dependencies, Docker might be overkill.

Learning Curve
If you’re new to Docker, there’s a learning curve. It might not be worth the effort for quick, one-off scripts or small-scale applications.

Performance Overhead
Docker containers have some performance overhead compared to running natively, which might be noticeable on resource-constrained systems.

Native Tools Are Sufficient
If your development stack already includes good dependency management tools (e.g., pipenv for Python, npm for JavaScript), you might not gain much from using Docker.

When to use docker while programming

Consistent Development Environment
Docker ensures that your application runs the same way on all machines, regardless of operating system or system configuration. This eliminates the “it works on my machine” problem.

Isolated Dependencies
Each Docker container has its own isolated environment. This means you can work on multiple projects with different dependencies (e.g., Python 3.10 for one project and 3.8 for another) without conflicts.

Simplified Onboarding
If you’re part of a team, new developers can quickly set up the project by running a Docker container instead of installing and configuring dependencies manually.

Microservices Development
Docker is ideal for developing microservices, as it allows you to run different parts of your application in separate containers.

Reproducible Builds
Docker enables you to test in an environment similar to production, reducing the likelihood of deployment issues.

Cross-Platform Compatibility
Applications packaged with Docker run consistently across different platforms (Windows, macOS, Linux).

Installation

Install docker for your machine (Win, Mac, Lin), once that is all done, on Windows you het a pop up oon wich to use Hyper-v or WSL (i chosed Hyper-V)

check if docker is installed in your machine

CMD/PWRSHL/BASH

docker

if you can see all the information on how docker works and what commands you can use, its installed!

If you don’t see this screen chances are it’s not installed, to install go to the official docker page:

Get Started with Docker

Dockerfile

a Dockerfile is the docker YAML code in the root of the folder. A Dockerfile is not YAML—it’s its own line-based, declarative syntax. People often mix it up with docker-compose.yml

It is a text file that tells Docker how to build an image, step by step.

  • One instruction per line
  • Each instruction creates a layer in the image
  • Read top → bottom

Here’s mine:

FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies
RUN npm install

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

EXPOSE 8080
CMD [ "http-server", "dist" ]

Common Dockerfile instructions

InstructionPurpose
FROMBase image (required)
WORKDIRSets working directory
COPYCopies files from host to image
ADDLike COPY, but with extras (archives, URLs)
RUNExecutes a command at build time
CMDDefault command when container starts
ENTRYPOINTFixed startup command
EXPOSEDocuments container port
ENVSets environment variables
ARGBuild-time variables
USERRun as non-root user

What Dockerfile is not

  • Not YAML
  • Not for defining multiple services
  • Not for runtime orchestration

That’s where docker-compose.yml comes in.

Dockerfile vs docker-compose.yml (YAML)

Dockerfiledocker-compose.yml
Builds one imageRuns multiple containers
Custom syntaxYAML
Image blueprintApp orchestration
docker builddocker compose up

Example docker-compose.yml:

services:
app:
build: .
ports:
- "3000:3000"

➡️ build: . points to the Dockerfile

Key best practices

  • Use small base images (alpine, slim)
  • Leverage layer caching (copy package.json first)
  • Use multi-stage builds for production
  • Avoid running as root
  • Keep images deterministic

Multi-stage example:

FROM node:20 AS builder
WORKDIR /app
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html

Why the confusion with YAML happens

Most real projects have both:

Dockerfile:  how to build
docker-compose.yml : how to run

They serve different but complementary roles.

Best Practices for Using Docker in Programming

Using Docker while programming is often beneficial, but whether you should use it depends on your specific needs and use case. Here’s a breakdown to help you decide:

  • Use Docker Compose to manage multi-container applications.
  • Keep Dockerfiles clean and modular.Regularly update your Docker images and dependencies to avoid security issues.
  • Mount your local code directory into the container for live development.

You should consider using Docker if your project involves multiple dependencies, team collaboration, or microservices, or if you want to ensure cross-environment consistency. For simpler projects, it might be an unnecessary complication. not saying you cant use them, you should for learning exposure and learn to think outside the box 🙂

Happy coding!

Pull my repo for this project!

Scroll to Top