Sign inSign up

pvital/docker_flask

By pvital

•Updated over 3 years ago

Docker setup to start a Flask project.

Image
0

1.1K

pvital/docker_flask repository overview

⁠docker_flask

Docker setup to start a Flask project.

(See "What's the difference between 'Shared' and 'Simple' tags?" in the FAQ⁠.)

⁠Simple tags

⁠How to use this image

⁠Create a Dockerfile in your Python app project
FROM pvital/docker_flask:latest

WORKDIR /usr/src/app

COPY . .

EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["-m", "flask", "run", "--host=0.0.0.0"]

You can then build and run the Docker image:

$ docker build -t <img_name>:[tag] .
$ docker run -it --rm -p 8080:5000 --name <app_name> <img_name>:[tag]

where:

  • <img_name> is the name of the Docker image for your project.
  • [tag] is an optional alias for this image. The default is latest.
  • <app_name> specifies a name with which you can refer to your container in subsequent commands.
⁠Run a simple Flask project

For many simple, single Flask projects, you may find it inconvenient to write a complete Dockerfile. In such cases, you can run a Flask application by using the docker_flask image directly:

$ docker run -it --rm \
  -p 8080:5000 \
  --mount type=bind,source="$PROJ_DIR",target=/app \
  --name <app_name> \
  pvital/docker_flask:latest

where:

  • $PROJ_DIR is the path to the project directory.
  • <app_name> specifies a name with which you can refer to your container in subsequent commands.

Now the Flask service is responding on port 8080 of your local host. Point your browser to http://127.0.0.1:8080/⁠ and enjoy the magic. If you want the application to listen to a different port, substitute the number 8080 from the command above with the desired one.

If you want to run the Flask application in a daemonized mode, execute the command with the -d argument:

$ docker run -d --rm \
  -p 8080:5000 \
  --mount type=bind,source="$PROJ_DIR",target=/app \
  --name <app_name> \
  pvital/docker_flask:latest

To terminate the execution, just type CTRL+C in the same console.

Tag summary

Content type

Image

Digest

sha256:0dbfa07de…

Size

51.5 MB

Last updated

over 3 years ago

docker pull pvital/docker_flask