Forwarding ports of other docker-compose services

I’m attempting to set up a development environment for a Node.js library that interfaces with RabbitMQ, the configuration for which is in the spoiler below.

Configuration files

I have a simple Dockerfile:


A docker-compose.yml file that boots up two services: main and rabbitmq:

version: "3"
      context: .
      dockerfile: Dockerfile
      - ..:/workspace:cached
    command: sleep infinity
      - 3000

    image: rabbitmq:3-management
    restart: unless-stopped
      - 5672
      - 15672

And finally a devcontainer.json file:

  "name": "Node.js & RabbitMQ",
  "dockerComposeFile": "docker-compose.yml",
  "service": "main",
  "workspaceFolder": "/workspace",
  "settings": {
    "": "/bin/bash"

This works wonderfully and the main service that I use to develop on can successfully reach the rabbit service and interact with it.

However, the RabbitMQ server exposes a helpful UI at port 15672 which I would like to be able to see, but I don’t know if it’s possible for me to get at it.

I can add "forwardPorts": [15672] to my devcontainer.json, but this seems to forward that port to my main service, when I want it to go to the rabbit service.

Is there any way to achieve this?

P.S. I’ve been eagerly awaiting Codespaces. I’m a huge fan of GitPod and this solution seems absolutely wonderful! Fantastic work; I can’t wait to get using it properly and start submitting feedback! :heart:

You can resolve this with a network trick - we’re going to update the samples at vscode-dev-containers with this.

Try adding the following to your main service:

network_mode: service:rabbit

That should make rabbit MQ available on localhost so the forwarding works properly.

1 Like

Fantastic! Works a charm. Thanks for such a speedy reply, @Chuxel, and thank you for doing amazing work with Codespaces!

1 Like