CraftedTemplate
Blog How to Deploy a Website with Docker (Step-by-Step Tutorial)

How to Deploy a Website with Docker (Step-by-Step Tutorial)

10/4/2025 • Festus Ayomike
How to Deploy a Website with Docker (Step-by-Step Tutorial)

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:

Code · batchfile
docker --version

Step 2: Create a Dockerfile

In your project root, add a file called Dockerfile:

For a static site (Nginx):

Code · batchfile
FROM nginx:alpine
COPY . /usr/share/nginx/html

For a Node.js app:

Code · batchfile
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]

Step 3: Build the Docker Image

Code · batchfile
docker build -t my-website .

Step 4: Run the Container

Code · batchfile
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

  1. Copy your files to a VPS (like DigitalOcean, AWS, or Linode).
  2. Install Docker on the server.
  3. 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.

Part of the Hosting Academy

Follow the full beginner → pro path to deploy any Crafted Template.

Browse the series →