Skip to content

Commit

Permalink
starting to dockerize flask app
Browse files Browse the repository at this point in the history
  • Loading branch information
FRM95 committed Sep 10, 2024
1 parent 47421da commit 0f4c729
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions geoheat.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10-slim

USER root
RUN mkdir /app
COPY ./requirements.txt /app
WORKDIR /app
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY ./src /app/src
WORKDIR /app/src

ENV FLASK_APP=app.py
ENV FLASK_DEBUG=1

CMD ["flask", "run", "--host=0.0.0.0"]
12 changes: 12 additions & 0 deletions mongo-tutorial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
When creating a docker mongodb container we must implement two steps to enhance security.

1. Authentication: we need to put some auth security when creating the docker container. Either in docker-compose or dockerfile.
What I did: In docker-compose, when adding an env file, this file needs to have 3 env variables: MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, MONGO_INITDB_DATABASE

2. Seeding and creating some database: after creating the container, it would be great to have some databases, collections and data so the app can use them.
What I did: Create a script file (.sh) which is going to be executed inmediately by the container after being up.
Using mongoimport command on the OS cli (container linux OS):
mongoimport --authenticationDatabase=$MONGO_INITDB_DATABASE -u=$MONGO_INITDB_ROOT_USERNAME -p=$MONGO_INITDB_ROOT_PASSWORD -d=<database> -c=<collection> --file=<filepath>
* we can add --drop to erase any old collection and --jsonArray if we have an array of documents (array of js objects/dictionaries)


0 comments on commit 0f4c729

Please sign in to comment.