vohzd.com

Docker Part Three: Deploy a Container to the Web

1 min read

We've built an image, provisioned a server, and set up Nginx with SSL. Time to actually get something running.

Step 1: SSH into your machine

Step 2: Run your container

Pull and run whatever image you like. I'm using the Express app from Part One:

docker run -p 3000:3000 -d vohzd/express

Step 3: Configure Nginx to proxy to it

Open your site config:

nano /etc/nginx/sites-available/example.com

Add a proxy_pass block to route traffic to your Docker container:

location / {
    try_files $uri $uri/ =404;
}

location /docker {
    proxy_pass http://localhost:3000/;
}

Step 4: Restart Nginx

systemctl restart nginx

Visit example.com/docker and you should see your app running. That's the entire Docker trilogy: build an image, set up a server, deploy the container.

Congratulations, you're now dangerously close to being a DevOps engineer. Don't let it go to your head.

Previous: Provision a VPS with Nginx and SSL