Deploy a Web App with Docker in 5 Minutes

Deploy a Web App with Docker in 5 Minutes

Photo by Wolfgang Weiser on Pexels

From Local Development to Live Deployment in Record Time

Deploying a web application used to involve complex server configuration, dependency management, and environment troubleshooting. Docker eliminates this complexity by packaging your application into a container that runs identically everywhere. This guide shows you how to deploy a web app from zero to live in under five minutes.

We will use a simple Node.js Express application as our example, but the same process works for Python, Ruby, Go, Java, or any other language. The beauty of Docker is that the deployment process is identical regardless of the technology stack.

Prerequisites

Docker Desktop installed and running. Verify with ‘docker –version’. No Node.js installation needed on your host machine because Docker provides the runtime inside the container.

Step 1: Create Your App

Create my-web-app directory with package.json and server.js for a basic Express server on port 3000. This is a standard setup you have probably done before, but we will never install Node.js on our host machine.

Step 2: Write the Dockerfile

Create a file named Dockerfile. Instructions: FROM node:20, WORKDIR /app, COPY package.json, RUN npm install, COPY ., EXPOSE 3000, CMD node server.js. About 10 lines total.

Step 3: Build the Image

‘docker build -t my-web-app .’ downloads the Node.js base image, installs dependencies, and creates a portable image. First build: 30-60 seconds. Subsequent builds: seconds due to caching.

Step 4: Run the Container

‘docker run -d -p 3000:3000 –name my-app my-web-app’. Open http://localhost:3000. Deployed in under two minutes.

Step 5: Push to Registry

Create a Docker Hub account. Tag with ‘docker tag my-web-app yourusername/my-web-app’. Push with ‘docker push yourusername/my-web-app’. Your image is available from any machine.

Step 6: Deploy to Server

SSH in, install Docker, pull, run with ‘–restart always’. For production, add Nginx reverse proxy and Let’s Encrypt SSL. This adds 10 minutes but makes it production-ready with HTTPS.

Troubleshooting

  • Container exits: check ‘docker logs container-id’
  • Port conflict: change host port mapping
  • Cannot access: check firewall rules
  • Permission denied: add user to docker group

Docker deployment turns a complex process into a few commands. Master these steps once and deploy any web application in minutes.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *