Docker
- Build docker image for flask-app & streamlit-app in local machine
docker build -f ./Docker/dockerfile.flask -t flask-app .or
docker build -f ./Docker/dockerfile.streamlit -t streamlit-app .- Push docker image to AWS ECR
docker tag [docker image name] 345345405651.dkr.ecr.ap-southeast-1.amazonaws.com/testing:streamlit-test
docker push 345345405651.dkr.ecr.ap-southeast-1.amazonaws.com/testing:streamlit-testAWS
-
Create Access Key
-
Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install- AWS Configure Setup
aws configure- Create Repository in ECR (Amazon Elastic Container Registry)
aws ecr create-repository --repository-name [repository name]- Login to AWS ECR through AWS CLI
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin [repository URI]sudo usermod -aG docker ubuntu
Terminal
- Get root permission
sudo su- Update apt-get
sudo apt-get update -y- Install Docker
sudo apt-get install -y docker.io docker-compose- Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker- Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install- Login to AWS ECR through AWS CLI
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin [repository URI]- Pull docker image from AWS ECR
docker pull [repository URI]:[docker image name/tag]- Run docker image
- map the container’s port 8501 to a host port 8501
docker run -p 8501:8501 <image_name>- Download Ngrok
curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \
&& echo "deb https://ngrok-agent.s3.amazonaws.com bookworm main" \
| sudo tee /etc/apt/sources.list.d/ngrok.list \
&& sudo apt update \
&& sudo apt install ngrok- Add Ngrok authtoken
ngrok config add-authtoken [authtoken]- Set telegram bot webhook
https://api.telegram.org/bot[telegram_bot_token]/setWebhook?url=[ngrok_url]- Deploy
- Run python script with
Screen
screen -S flask-app
docker run -p 5000:5000 <image_name>
screen -S ngrok
ngrok http http://localhost:5000
screen -S streamlit-app
docker run -p 8501:8501 <image_name>- Run docker-compose with
Screen
screen -S tg_bot_docker_compose
sudo docker-compose up --build