Fast Docker, Python, Flask deployment on Linux | Raspberry Pi Example

Pubblicato il: 24 gennaio 2024
sul canale di: Skill Collectors
257
9

Instructions for your copying and pasting pleasure:

1. Install Docker on Ubuntu
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker --version # Verify installation

You will need to add your user to the Docker group, add the user with the command below and restart the shell session.
sudo usermod -aG docker insert-your-username-here

2. Create a Basic Flask App

Create a new directory and navigate into it:
mkdir flask_app && cd flask_app

Create app.py:
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello, World!'

if _name_ == '__main__':
app.run(host='0.0.0.0', port=5000)


Create requirements.txt:
Flask

3. Dockerize the Flask App

Create a Dockerfile:
FROM python:3.8-slim

WORKDIR /app

COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY . /app

EXPOSE 5000

CMD ["python", "app.py"]

Build the Docker image:
docker build -t myflaskapp .

Run the container:
docker run -d -p 5000:5000 --restart=always myflaskapp


In questa pagina del sito puoi guardare il video online Fast Docker, Python, Flask deployment on Linux | Raspberry Pi Example della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Skill Collectors 24 gennaio 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 257 volte e gli è piaciuto 9 spettatori. Buona visione!