0

I have a websocket server running locally on port 3000. This websocket server is NOT dockerized. I also have a websocket client (myclient) which IS dockerized. The myclient is communicating with another dockerized microservice (anothermicroservice) via named bridge network (mybridgenet). I would like the myclient to connect to the websocket server, which as mentioned is not dockerized and it is running at 127.0.0.1:3000. Since 127.0.0.1 for the myclient is the container's address I cannot simply use it as such. My question is, How do I keep the communication between myclient and anothermicroservice via the bridge network, and at the same connect the myclient to the non-dockerized websocket server at the localhost 127.0.0.1:3000?

I tried to use the network_mode host option but it cannot work together with networks

My docker-compose file is as following:

version: '3.7'

services:

    myclient:
        container_name: 
            myclient
        hostname:
            myclient
        build: 
            context: 
                .
        dockerfile: 
            Dockerfile
        depends_on:
            - anothermicroservice
        env_file:
            - server.env # within this file I have the server uri 127.0.0.1:3000
        networks:
            - mybridgenet

    anothermicroservice:
        container_name: 
            anothermicroservice
        hostname:
            anothermicroservice
        build: 
            context: 
                ../anothermicroservice
        dockerfile: 
            Dockerfile
        networks:
            - mybridgenet

networks:   
  mybridgenet:
    name:
      mybridgenet
    driver: 
      bridge
user1064089
  • 99
  • 2
  • 4
  • 10
  • That sounds like you need to fix the server hostname in `server.env` to be the name of the other container (`anothermicroservice`); as you note, it isn't `localhost` because each container is its own `localhost`. – David Maze May 08 '19 at 19:50
  • Hi David. I do not think you understood the question. I have 2 dockerized services (myservice, anothermicroservice), plus 1 non-dockerized websocket server. The server.env has the IP of the non-dockerized websocket server, not the anothermicroservice – user1064089 May 08 '19 at 20:11
  • 1
    Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze May 08 '19 at 20:22
  • Oh, sorry. It's still not 127.0.0.1 ("this container"), but the answers to this question list out basically all of the possibilities; it is a little dependent on the host environment. – David Maze May 08 '19 at 20:23

0 Answers0