From 66c843237eabf2f8875a4723f7e1d2a03770cd50 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 21 Dec 2020 03:24:12 +0100 Subject: [PATCH] Make project docker ready --- projects/project-3/backend/.dockerignore | 2 ++ projects/project-3/backend/Dockerfile | 9 +++++++++ projects/project-3/backend/README.md | 14 +++++++++++++- projects/project-3/backend/requirements.txt | 8 ++++---- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 projects/project-3/backend/.dockerignore create mode 100644 projects/project-3/backend/Dockerfile diff --git a/projects/project-3/backend/.dockerignore b/projects/project-3/backend/.dockerignore new file mode 100644 index 0000000..9adde20 --- /dev/null +++ b/projects/project-3/backend/.dockerignore @@ -0,0 +1,2 @@ +bike-data.db +*.log \ No newline at end of file diff --git a/projects/project-3/backend/Dockerfile b/projects/project-3/backend/Dockerfile new file mode 100644 index 0000000..1bb3617 --- /dev/null +++ b/projects/project-3/backend/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9 + +WORKDIR /app + +COPY requirements.txt /app + +RUN pip install -r requirements.txt + +CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file diff --git a/projects/project-3/backend/README.md b/projects/project-3/backend/README.md index d145ee1..23cb7b3 100644 --- a/projects/project-3/backend/README.md +++ b/projects/project-3/backend/README.md @@ -18,4 +18,16 @@ Note: The importer outputs logs to the terminal, and the db_init.log file. ## 3. Start the backend To start the backend, you first have to initialize the database! - \ No newline at end of file +### Run with docker +Switch into the project directory, then run: +```shell +docker build -t geovis-backend . +``` +After the build make sure you are in the same directory as "bike-data.db" resides, if so, run +```shell +docker run -v $(pwd):/app -p 8080:80 --restart always -d test +``` + +Note: `$(pwd)` puts the current directory in the command, if you are on Windows, you can use WSL or provide the full path by typing it out. + +To stop just shut down the container. \ No newline at end of file diff --git a/projects/project-3/backend/requirements.txt b/projects/project-3/backend/requirements.txt index e979d3d..3fd40cb 100644 --- a/projects/project-3/backend/requirements.txt +++ b/projects/project-3/backend/requirements.txt @@ -1,4 +1,4 @@ -requests~=2.25.1 -fastapi[all]~=0.62.0 -uvicorn~=0.13.1 -pydantic~=1.7.3 \ No newline at end of file +requests +fastapi[all] +uvicorn +pydantic \ No newline at end of file