Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000 8001 8002
CMD ["python", "server.py"]
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,36 @@ An example of how a question and its details is stored in the database:
```

As shown in the above example, one question can be answered by many users and each user is represented by his ID

# Running on Docker

- In order to run the project on docker for the **first time**, ***or*** you have updated the server, run the following commands in terminal:

```shell
cd path/to/your/project
docker-compose build
docker-compose up
```

- If you have already run the above commands before, and you just want to run the server on docker run the following command:

```shell
docker-compose up
```

- To stop the server run the following command:

```shell
docker-compose down
```

- Since the default environment is the `dev` the docker will run using `.env.dev` file on port `8002`.
- The docker file also exposed to ports `8000` and `8001`. So in order to run in `prod` environment you must change `globals.env_status` to `prod` which will run the docker on port `8001`.

- To push the docker image to the docker hub you have to build it first and then run the following commands in the terminal:

```shell
docker tag <your-image-name> <your-docker-username>/<the-image-name-you-want-to-have-at-dockerhub>:<your-image-tag>
docker login
docker push <your-docker-username>/<the-image-name-you-want-to-have-at-dockerhub>:<your-image-tag>
```
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.8"
services:
server:
build: .
ports:
- "8000:8000"
- "8001:8001"
- "8002:8002"
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_routes():
# start server
add_routes()
port = 8002 if globals.env_status == "dev" else 8001
uvicorn.run(app, host="127.0.0.1", port=port)
uvicorn.run(app, host="0.0.0.0", port=port)

except Exception as e:
print(e)
Expand Down