Before we start, there are definitely some prerequisites regarding this.
Prerequisites
An Ubuntu 20.04 server
Firewall rules allowing ssh on port 22, HTTP on port 80 and HTTPS on port 443 access
A static Public IP for the server
Ability to SSH into the server
A root password for the server as it will be needed in few steps
- (If you use an Private Key (.pem file) to SSH into the server, SSH into the server and use
sudo passwd <YOUR USERNAME>
to create a new password)
- (If you use an Private Key (.pem file) to SSH into the server, SSH into the server and use
An Account on Docker Hub with a private repository created (You can use any registry, just look up the instructions to do
docker login
.
SSH Into the Server
Install Docker
Update the package database for Docker and Make sure you are about to install from the Docker repo instead of the default Ubuntu repo
Finally install and check if Docker daemon is running
Give docker command sudo privileges
Confirm that you're in the docker group
References: DigitalOcean
Install Docker Compose
References: DigitalOcean
Get access token from Docker Hub
Login to Docker Hub
Go to Account Settings
Go to Security
Click on New Access Token
Give your token a name
Generate new token and copy it somewhere safe and accessible and close the dialog box.
Login to Docker Hub
Login to Docker Hub on your server
Make the docker-compose.yml file
Paste the Following Do note that you can change the number of services according to your preference
Setup Nginx
Install Nginx
Start and Enable Nginx
Edit conf file for basic http server
Paste the following Configuration
Here also you've to keep the number of services in mind. If you're using only one container, remove the /api
block
Restart Nginx
Starting the HTTP Server
Setup your Domain
Enter the Public IP of your server in the DNS records of your Domain name as A Record, and your website should be up and running with HTTP on the domain.
Setting Up HTTPS and SSL with LetsEncrypt and CertBot
Install Prerequisites
Install CertBot
Enter all the follow up inputs required while generating certificate.
Test Automatic Renewal
Confirm that HTTPS is active now
Go to the your domain in your browser, and click on the Padlock to verify that the certificate issued is by LetsEncrypt.
References: Certbot
Thank you for reaching at the end of the post. If you liked it, please share it among your network. If you found any errors/discrepenceies, you can contact me any time on my mail or fill the contact form on my Portfolio, and I'll get back to you.