This repo is a template to run flask with docker-compose that is scalable and and uses a domain name.
- docker
- docker-compose
- python
- flask
- nginx
- Ubuntu 22.04 Server
- domain
- Create 'A' record to ubuntu server's IP address with "@" as hostname
- Create 'A' record to ubuntu server's IP address with "www" as hostname
sudo apt-get update
sudo apt-get upgrade
How to install docker in Ubuntu 22.04
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
Install Docker Compose on Ubuntu 22.04
sudo apt install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
docker compose version
sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
systemctl status nginx
sudo rm /etc/nginx/sites-enabled/default
sudo nano /etc/nginx/sites-enabled/<whatever you want, no spaces>
type the text below in the /etc/nginx/sites-enabled/<whatever you want, no spaces> then save it
server {
listen 80;
server_name www.insertdomainhere.com insertdomainhere.com;
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}
sudo ufw allow http/tcp
sudo ufw allow ssh
sudo ufw allow https
sudo ufw enable
sudo ufw status
apt-get update
sudo apt-get install certbot
apt-get install python3-certbot-nginx
nginx -t && nginx -s reload
sudo certbot --nginx -d insertdomainhere.com -d www.insertdomainhere.com
Create a folder inside nginx and name it ssl
Get the contenst of fullchain.pem
sudo nano /etc/letsencrypt/live/insertdomainhere.com/fullchain.pem
copy and save it inside ./nginx/ssl/fullchain.pem
Get the contenst of privkey.pem
sudo nano /etc/letsencrypt/live/insertdomainhere.com/privkey.pem
copy and save it inside ./nginx/ssl/privkey.pem
sudo systemctl stop nginx
docker-compose up --build --scale web=3
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
https://business-science.github.io/shiny-production-with-aws-book/https-nginx-docker-compose.html