Introduction
Docker is a tool that lets you package applications into containers — lightweight, portable environments that run anywhere. Instead of worrying about different servers or dependencies, Docker makes deployment consistent.
This guide shows you how to deploy a website with Docker.
Why Use Docker?
- Works the same everywhere (local → staging → production)
- Easier to move projects between servers
- Supports scaling with Docker Compose or Kubernetes
- Ideal for developers building APIs or full-stack apps
Step 1: Install Docker
Follow the official guide for your OS: Docker Install.
Verify installation:
docker --version
Step 2: Create a Dockerfile
In your project root, add a file called Dockerfile
:
For a static site (Nginx):
FROM nginx:alpine
COPY . /usr/share/nginx/html
For a Node.js app:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
Step 3: Build the Docker Image
docker build -t my-website .
Step 4: Run the Container
docker run -d -p 8080:80 my-website
Now visit:
http://localhost:8080
Your site is running in Docker
Step 5: Deploy to a Server
- Copy your files to a VPS (like DigitalOcean, AWS, or Linode).
- Install Docker on the server.
- Build and run your container there.
For multiple services (API + frontend + DB), use docker-compose.yml
to define everything.
Troubleshooting
- Port already in use? Stop other apps from using that port.
- Build errors? Check the
Dockerfile
syntax and dependencies. - Site not accessible remotely? Open the firewall port (80/443).
Conclusion
Docker gives you full control over deployments and makes apps portable across environments. It’s a powerful step toward DevOps and modern hosting.
Coming up in Hosting Academy: we’ll look at CI/CD pipelines for automated deployments.