docker (6 Part Series)
1 Joomla + MySql + phpMyAdmin in Docker
2 kong api gateways with docker
… 2 more parts…
3 Dockerize an existing Rails application
4 Dockerize a Flask App
5 Dockerize an existing GOLANG web server
6 Dockerize an existing Laravel application with docker-compose
How dockerize a Flask app…
here my very basic app:
main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
Enter fullscreen mode Exit fullscreen mode
N.B: above I have set public ip 0.0.0.0, beacuse with 127.0.0.1 it’s reachable only inside the container and not from the outside outside.
create a file requirements.txt
and insert all the pip libraries that your app require (in my case only Flask).
requirements.txt
flask
Enter fullscreen mode Exit fullscreen mode
create a file named Dockerfile:
FROM ubuntu:18.04
LABEL maintainer “yor name <your@email.com>”
RUN apt-get update -y && \
apt-get install -y python3-pip python3-dev
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip3 install -r requirements.txt
COPY . /app
ENTRYPOINT [ “python3” ]
CMD [ “main.py” ]
Enter fullscreen mode Exit fullscreen mode
build the image launching from terminal the command:
docker build -t name_of_yuor_image:latest .
run the container launching from terminal the command:
docker run --name name_your_container -p 5000:5000 -d name_of_yuor_image:latest
connected to address: http://0.0.0.0:5000
Watch the video tutorial:
docker (6 Part Series)
1 Joomla + MySql + phpMyAdmin in Docker
2 kong api gateways with docker
… 2 more parts…
3 Dockerize an existing Rails application
4 Dockerize a Flask App
5 Dockerize an existing GOLANG web server
6 Dockerize an existing Laravel application with docker-compose
暂无评论内容