Develop applications in Node.js and PostgreSQL. Includes Node.js, eslint, and yarn in a container linked to a Postgres DB container
| Options Id | Description | Type | Default Value |
|---|---|---|---|
| imageVariant | Node.js version (use -bookworm, -bullseye variants on local arm64/Apple Silicon): | string | 22-bookworm |
This template references an image that was pre-built to automatically include needed devcontainer.json metadata.
- Image: mcr.microsoft.com/devcontainers/javascript-node (source)
- Applies devcontainer.json contents from image: Yes (source)
This definition creates two containers, one for Node.js and one for PostgreSQL. You will be connected to the Node.js container, and from within that container the PostgreSQL container will be available on localhost port 5432. The default database is named postgres with a user of postgres whose password is postgres, and if desired this may be changed in docker-compose.yml. Data is stored in a volume named postgres-data.
While the definition itself works unmodified, it uses the mcr.microsoft.com/devcontainers/javascript-node image which includes git, eslint, zsh, Oh My Zsh!, a non-root vscode user with sudo access, and a set of common dependencies for development.
You also can connect to PostgreSQL from an external tool when connected to the Dev Contaner from a local tool by updating .devcontainer/devcontainer.json as follows:
"forwardPorts": [ "5432" ]You can add other services to your docker-compose.yml file as described in Docker's documentaiton. However, if you want anything running in this service to be available in the container on localhost, or want to forward the service locally, be sure to add this line to the service config:
# Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:dbBy default, web frameworks and tools often only listen to localhost inside the container. As a result, we recommend using the forwardPorts property to make these ports available locally.
"forwardPorts": [9000]The ports property in docker-compose.yml publishes rather than forwards the port. This will not work in a cloud environment like Codespaces and applications need to listen to * or 0.0.0.0 for the application to be accessible externally. Fortunately the forwardPorts property does not have this limitation.
Note: This file was auto-generated from the devcontainer-template.json. Add additional notes to a NOTES.md.