This definition creates two containers, one for Node.js and one for PostgreSQL. VS Code will attach 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 using VS Code 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:db