Docker Community Forums

Share and learn in the Docker community.

Trying to access Linux Container from Windows host via Node.js server. Can't make a connection happen

I have researched endless sources for an answer, but I simply can’t get this to work. I’ve read about the shortcomings between Docker for WIndows and port-mapping, etc., and unfortunately the workarounds haven’t pointed me at success. I should add that I have little to no background in docker, and that I run Docker Desktop for Windows. Many sources are talking about docker run commands, but I know little about how to integrate that with the environment Docker Desktop already creates for me via docker-compose up -d.

What I am trying to do:

  • Run my Node.js server locally on localhost:4444 (Windows 10). This provides a graphql playgound.
  • The Node server should communicate with a Prisma server. The Prisma server exposes port 4466 from within a Linux container (standard per the docs), and to my Windows machine so that graphql can write modifications to it.
  • A MySql database runs in parallel to the Prisma server from inside its own Linux container.

What I’ve tried:

  • grab all kinds of IPs from ipconfig, docker ps, change bridge as the network_mode, and some other things.

docker-compose.yaml:

version: "3.7"
services:
  prisma:
    image: prismagraphql/prisma:1.34.10
    restart: always
    container_name: prisma_1
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        managementApiSecret: my-secret
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
            rawAccess: true
            migrations: true
  mysql:
    image: mysql:8.0.20
    restart: always
    container_name: db_1
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
volumes
  mysql:

Please help me get this to work once and for all. I’ve already spent entirely too many days trying to figure this out.

Where or how do I get the appropriate IP on Windows 10 to connect my local server to the Docker container?
If it’s not an IP issue, what do I need to do to connect the two servers?

Your node.js Server is not hosted in docker?
The clean solution would be to move the node.js server in docker aswell. This will make everything clean and easy.
This should probably do the job, but doesn’t work in Docker Desktop. https://docs.docker.com/network/network-tutorial-host/

What you can also do is to search for the node.js server on the ip docker0:4444. The interface docker0 should represent your hosts ip. (https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container)

Ideally only the Prisma server and the database are inside Docker. The node server being inside as well shouldn’t make a difference to the issue because at some point the containers will have to communicate to the outside.

Unfortunately, it seems that the docker0 bridge is unavailable on Windows, see here.

The same page talks about using docker run, like so many other resources before. Given that I have the above docker-compose file, how do I make sure all those arguments are represented via tags on my docker run command? It would be a really really long command to enter, between docker run -d -p -h -xxx etc

Docker Desktop has many problems. It is possible that what you want is straight impossible.

[…] at some point the containers will have to communicate to the outside.

Do you mean that then containers need to be accessible from the outside because thats no problem. Or do you mean that the containers need to access something from the outside?

Docker-Compose is just a wrapper for docker service create (which can be almost equal to docker run). (Almost) any docker run / service create command can be converted to a docker-compose file and vice versa. To convert one to another you have to translate the statements using the docker-compose reference (https://docs.docker.com/compose/compose-file/) and the docker run reference (https://docs.docker.com/engine/reference/commandline/run/)

Convertings this part

services:
  prisma:
    image: prismagraphql/prisma:1.34.10
    restart: always
    container_name: prisma_1

results to the run command

docker run --restart always --name prisma_1 prismagraphql/prisma:1.34.10

As an example for the restart part:

  • Take a look at the docker-compose reference what restart does
  • Then search in the docker run or service create reference how to archieve the same (The commands are mostly equal or simmilar)