6

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
lsd
  • 504
  • 1
  • 4
  • 16
  • why not ssh into the container and see if the setup is fine, you can also try some curl command to see if the service is running as expected – cerofrais Jul 06 '20 at 09:41
  • I can curl the localhost: form the ubuntu itself. And as I mentioned, the compose is already tested and working fine on prod, so the services are running as they should. It seems as a mapping issue between windows and the wsl. – lsd Jul 06 '20 at 10:08
  • I have docker for windows installed on my machine (i.e. installed in Windows not in Ubuntu). It can be accessed from within WSL2 almost as if it were installed locally. – Henry Jul 06 '20 at 10:13
  • Good for you. Thanks for reviewing this question. – lsd Jul 06 '20 at 10:15
  • can you show the error, also can you show how you are doing the port mapping? also, I guess you made sure that the port you are exposing and port you are mapping is same – cerofrais Jul 06 '20 at 10:36
  • There is no error. It just times out when trying to reach the localhost:15672. I got both ports allowed by inbound rune in win firewall, and yet it cannot be reached. I have curled the localhost from the bash, and that works as expected, but it never loads from chrome or firefox. – lsd Jul 10 '20 at 06:51

2 Answers2

18

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 ipconfig in the docker container:

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

ipconfig results

4wk_
  • 2,458
  • 3
  • 34
  • 46
lsd
  • 504
  • 1
  • 4
  • 16
  • 3
    Consider adding info on how to get the above info :) Running `ifconfig` gives the above output. If your distro doesn't have it, it can be installed with: `sudo apt install net-tools` – Johny Skovdal Jan 29 '22 at 22:11
  • 2
    You can also use `ip addr` to pull up interfaces if you do not have net-tools (IE `ifconfig`) – John Aug 06 '22 at 21:15
  • after getting inside the container by running `docker exec -it CONTAINER_ID bash`, i get not found when hitting **ifconfig**, **ipconfig** or **ip addr**. outside the container, when i hit ipconfig, i do get the result like shown in the above answer pic, and but when i hit the INETVALUE:PORT_EXPOSED in the browser of my windows machine, i am still gettin "this site can't be reached " could you please tell me what i am doing wrong – Suraj Oberai May 24 '23 at 12:25
1

Your may also try to expose wsl ports to windows, using this script https://gist.github.com/xmeng1/aae4b223e9ccc089911ee764928f5486

I have troubles while connecting to wsl via ssh, and manage to do it after using this