Closed ngillux closed 1 year ago
Cross-posted in https://github.com/freeCodeCamp/classroom/pull/390#issuecomment-1654928638 https://github.com/freeCodeCamp/classroom/pull/396#issuecomment-1654929232
Originally posted at https://github.com/freeCodeCamp/classroom/pull/385#issuecomment-1652379813
@ngillux @utsab If this needs to be clarified live, we can schedule a call to discuss it further. Thanks!
This sudo service postgresql start
manual step is redundant because there is already a db
container that runs PostgreSQL on TCP port 5432, so there isn't a need to start the PostgreSQL service inside the app
container.
There are two containers simultaneously running in GitHub Codespaces:
app
containerdb
containerThe app
container is configured in the top part of the .devcontainer/docker-compose.yml
file via:
https://github.com/freeCodeCamp/classroom/blob/main/.devcontainer/docker-compose.yml#L1-L30
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/javascript-node-postgres/.devcontainer/docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
# Update 'VARIANT' to pick an LTS version of Node.js: 20, 18, 16, 20-bookworm, 18-bookworm, 16-bookworm 20-bullseye, 18-bullseye, 16-bullseye, 20-buster, 18-buster, 16-buster
# Append -bullseye or -buster to pin to an OS version.
# Use -bookworm, and -bullseye variants on local arm64/Apple Silicon.
VARIANT: 20-bookworm
volumes:
- ..:/workspace:cached
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db
# Uncomment the next line to use a non-root user for all processes.
# user: node
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
The db
container is configured in the bottom part of the .devcontainer/docker-compose.yml
file via:
https://github.com/freeCodeCamp/classroom/blob/main/.devcontainer/docker-compose.yml#L31-L45
db:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
volumes:
postgres-data:
and its TCP 5432 port is forwarded to the app
container via https://github.com/freeCodeCamp/classroom/blob/main/.devcontainer/devcontainer.json#L36-L38
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or with the host.
"forwardPorts": [3000, 3001, 5432, 5555],
To recap: If this needs to be clarified live, we can schedule a call to discuss it further. Thanks!
Relates to https://github.com/freeCodeCamp/classroom/pull/390 and https://github.com/freeCodeCamp/classroom/issues/395
Checklist:
Update index.md
)