Skip to content

Commit

Permalink
networking bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 15, 2024
1 parent 71b8b6f commit acc79ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ FROM mcr.microsoft.com/devcontainers/python:3.12
ENV PYTHONUNBUFFERED 1

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends parallel vim
&& apt-get -y install --no-install-recommends parallel vim \
&& apt-get -y install --no-install-recommends redis-server

ENV PGHOST=localhost
ENV PGUSER=postgres
Expand Down
15 changes: 10 additions & 5 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ services:
build:
context: .
dockerfile: Dockerfile

volumes:
- ..:/workspaces/pigeon:cached

command: sleep infinity

network_mode: service:database
networks:
- backend

redis:
image: redis/redis-stack-server:7.2.0-v6
Expand All @@ -20,7 +18,8 @@ services:
- "6379:6379"
volumes:
- data:/home/pigeon
network_mode: service:database
networks:
- backend

database:
image: postgres:16
Expand All @@ -32,6 +31,12 @@ services:
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: pigeondb
networks:
- backend

volumes:
data:

networks:
backend:
driver: bridge
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ cd client
npm run dev
```

The postgres and redis services are running on the same network as the dev container, but they can only communicate with each other via the designated service names, which are `database` and `redis` respectively. If you want to view these services from inside the dev container, you can use the following commands:

```sh
# postgres
PGPASSWORD='password' psql -h database -U postgres

# redis
redis-cli -h redis
```

Alternatively, you can access these services from your local machine, i.e., outside of the dev container, by connecting directly to the docker containers. To do this, run

```sh
docker container ls
```

and retrieve the container id of your desired instance (e.g., `pigeon_devcontainer-database-1`). Then, run

```sh
docker exec -it <container_id> /bin/bash
```

to enter the container, from which you should be able to run `psql` or `redis-cli` directly.

### Installing Python Dependencies

Put all direct dependencies (i.e., packages we directly import) in `requirements.in`. pigar can be used to automate part of this process. Then, run
Expand Down

0 comments on commit acc79ce

Please sign in to comment.