dockerubuntu-20.04windows-subsystem-for-linux

How to access docker containers on wsl 2


I am having Ubuntu 20.04 LTS running on wsl 2. I have installed docker according to this guide https://docs.docker.com/engine/install/ubuntu/. I have a stack with few services (basically I want to set up an environment to test my services before pushing to prod), the stack is running as expected on production, there are portainer and RabbitMq running on it and they are accessible on the network.

However, when I deploy the same stack (via docker-compose.yml) on the docker that I have installed on the ubuntu on wsl 2 I can not access the RabbitMq and the Portainer services using localhost/127.0.0.1:<the published port/s>. The containers are running stable from what I see with "docker container ls".

I have tried to set an inbound rules in the firewall - nop luck.

Here is the whole service setup from the docker-compose.yml:

  rabbitmq:
    image: rabbitmq:3-management
    logging:
      driver: "json-file"
      options:
        max-file: 3
        max-size: 5m
    hostname: rabbitmq
    deploy:
      resources:
        limits:
          memory: 200M
        reservations:
          memory: 199M
    ports:
      - 15672:15672
      - 5672:5672
    env_file:
      - .env
    networks:
      - webnet

Solution

  • Alright, it turns out that I should have used the ip of the eth0 interface. Now I can access the services form the host/win.

    Just type ifconfig in the docker container:

    (if it return "command not found" you can install it with: sudo apt install net-tools)

    ipconfig results