I have a docker compose setup that has a few different containers running, but the main container that I am actually working with is a node.js project that does not actually have any exposed ports, as the project itself doesn’t need them. It is a chat bot that simply responds to commands when prompted. Is there any way I can get a VS Code debugger to connect to it when running so that I can debug any issues?
You can see here that all 3 other services have port mappings, but the digittron-bot
is blank in the ports column. Building and running the compose file works just fine, but when attempting to attach the VS code debugger, I get: Error: Could not connect to debug target at http://localhost:9229: Could not find any debuggable target
. Am I correct in assuming that localhost path is a VS code default? How can I tell it to connect to my “bot” container?
docker ps output:
IMAGE COMMAND CREATED STATUS PORTS NAMES
digittron-bot "docker-entrypoint.s…" 23 minutes ago Up 17 minutes bot
timothyjmiller/prisma-studio:latest "/bin/sh prisma-intr…" 27 minutes ago Up 27 minutes 0.0.0.0:5555->5555/tcp prisma-studio
postgres:16.2 "docker-entrypoint.s…" 2 hours ago Up 17 minutes (healthy) 0.0.0.0:5432->5432/tcp postgres
redis:7.2.4 "docker-entrypoint.s…" 2 hours ago Up 17 minutes (healthy) 0.0.0.0:6379->6379/tcp redis
My docker-compose file:
name: digittron
services:
prisma-studio:
container_name: prisma-studio
image: timothyjmiller/prisma-studio:latest
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
profiles:
- dev
environment:
# prisma studio requires the env variable name be POSTGRES_URL
POSTGRES_URL: ${DATABASE_URL}
ports:
- ${PRISMA_STUDIO_PORT}:${PRISMA_STUDIO_PORT}
postgres:
image: postgres:16.2
container_name: postgres
hostname: postgres
environment:
POSTGRES_USER: ${PSQL_USER}
POSTGRES_PASSWORD: ${PSQL_PASS}
POSTGRES_DB: ${PSQL_DB_NAME}
ports:
- ${PSQL_PORT}:${PSQL_PORT}
restart: 'unless-stopped'
volumes:
- 'pg-data:/var/lib/postgresql/data'
healthcheck:
test: ['CMD-SHELL', 'pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER']
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7.2.4
container_name: redis
restart: always
ports:
- ${REDIS_PORT}:${REDIS_PORT}
command: redis-server --save 20 1 --loglevel warning
volumes:
- 'cache:/data'
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
bot:
container_name: bot
build:
context: .
args:
DATABASE_URL: ${DATABASE_URL}
secrets:
- npmrc
- npmrc_prod
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
tty: true
environment:
DATABASE_URL: ${DATABASE_URL}
env_file:
- ./src/.env
volumes:
pg-data:
driver: local
cache:
driver: local
secrets:
npmrc:
file: .npmrc
npmrc_prod:
file: .npmrc