Skip to content

Commit 5727674

Browse files
committed
Fix broken dockerfile
Fix docker not exposing port and binding ip correctly
1 parent 7215dac commit 5727674

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
FROM python:3.13
2+
ARG PORT=2000
23
WORKDIR /code
34
COPY ./requirements.txt /code/requirements.txt
45
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
56
COPY ./restapi /code/restapi
67

7-
CMD ["python", "-m", "restapi"]
8+
CMD ["fastapi", "run", "restapi/main.py", "--port", "2000"]
9+
EXPOSE ${PORT}

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,55 @@ This was designed to be used with RabbitMQ, but likely will work with any AMQP-b
1212
- pip
1313

1414
### Environment Variables
15-
- `RPC_URI`: The URI of the message broker. E.G `amqp://guest:guest@localhost/`
16-
- `PORT`: The port to run the application on. (Default: 2000)
15+
- `RPC_URI`: The URI of the message broker. E.G `amqp://guest:guest@localhost:5672/`
1716

1817
### Docker
19-
You cause pull the container from Github container registry
18+
You can run the container by pulling from Github container registry
2019
```bash
21-
docker pull ghcr.io/iplsplatoon/AMQP-restapi:master
20+
docker run ghcr.io/iplsplatoon/AMQP-restapi:master -p 2000:2000 -e RPC_URI=amqp://guest:guest@localhost:5672/
2221
```
2322

2423
or use `ghcr.io/iplsplatoon/ampq-restapi:master` as the image name in your docker-compose file.
2524

25+
Example `docker-compose` file:
26+
```yaml
27+
services:
28+
rabbitmq:
29+
image: rabbitmq:3-management-alpine
30+
restart: unless-stopped
31+
container_name: 'rabbitmq'
32+
ports:
33+
- "5672:5672"
34+
- "15672:15672"
35+
volumes:
36+
- ./volumes/rabbitmq/data/:/var/lib/rabbitmq/
37+
- ./volumes/rabbitmq/log/:/var/log/rabbitmq
38+
rest-amqp:
39+
image: b9d1a35b
40+
ports:
41+
- "2000:2000"
42+
environment:
43+
RPC_URI: amqp://guest:guest@rabbitmq:5672
44+
```
45+
2646
### Install: Bare Metal
47+
You can run the application using the Fastapi CLI
48+
2749
1. Install python dependencies with pip
2850
```bash
2951
pip install -r requirements.txt
3052
```
3153

32-
3. Run the application
54+
2. Run the application
3355
```bash
34-
python -m restapi
56+
fastapi dev restapi/main.py
3557
```
3658

59+
#### Ports
60+
The application will run on port `2000` by default. In docker you can change this by changing the `-p` flag in the
61+
docker run command or in your docker-compose file. For bare metal, you can change the port by using the `--port`
62+
3763
### Making requests
38-
The application will run on port 2000 by default.
3964

4065
#### Docs
4166
The application is documented using OpenAPI.

restapi/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from restapi.routes import rpc_router
88

99
rpc_uri = os.getenv("RPC_URI")
10-
port = int(os.getenv("PORT", 2000))
1110
if not rpc_uri:
1211
raise ValueError("RPC_URI environment variable is not set.")
1312

@@ -37,4 +36,4 @@ def create_app():
3736

3837
app = create_app()
3938
if __name__ == "__main__":
40-
uvicorn.run(app, host="localhost", port=port)
39+
uvicorn.run(app, host="localhost", port=2000)

0 commit comments

Comments
 (0)