Chameleon
Chameleon

Reputation: 10128

How to access container from host using IP ADDRESS in Docker Desktop Windows 10 (esspecially with use docker compose)?

What should I do to access container via IP ADDRESS not PORT? Can I define any kind of network or bridge?

I am using standard Docker Desktop with WSL2 on Windows 10. This required to expose containers as machines not as ports.

I try this but is not works :)

This compose is very complex but you can use pure Ubuntu image to test it - not matter what image.

networks:
  cassandra:
volumes:
  cassandra-data-1:
    driver: local
  cassandra-log-1:
    driver: local
  cassandra-data-2:
    driver: local
  cassandra-log-2:
    driver: local
  cassandra-data-3:
    driver: local
  cassandra-log-3:
    driver: local
  cassandra-data-4:
    driver: local
  cassandra-log-4:
    driver: local

services:
  cassandra-1:
    image: cassandra:4.0.5
    container_name: cassandra-1
    hostname: dc-cassandra-1
    mem_limit: 2g
    networks:
      - cassandra
    environment: &cassandra_environment
      MAX_HEAP_SIZE: 1G
      HEAP_NEWSIZE: 100M
      CASSANDRA_SEEDS: dc-cassandra-1,dc-cassandra-2,dc-cassandra-3,dc-cassandra-4
      CASSANDRA_CLUSTER_NAME: dptr-v2
      CASSANDRA_DC: dptr-v2-dc0
      CASSANDRA_RACK: dptr-v2-r0
    volumes:
      - cassandra-data-1:/var/lib/cassandra
      - cassandra-log-1:/var/log/cassandra

  cassandra-2:
    image: cassandra:4.0.5
    container_name: cassandra-2
    hostname: dc-cassandra-2
    mem_limit: 2g
    networks:
      - cassandra
    environment: *cassandra_environment
    volumes:
      - cassandra-data-2:/var/lib/cassandra
      - cassandra-log-2:/var/log/cassandra

  cassandra-3:
    image: cassandra:4.0.5
    container_name: cassandra-3
    hostname: dc-cassandra-3
    mem_limit: 2g
    networks:
      - cassandra
    environment: *cassandra_environment
    volumes:
      - cassandra-data-3:/var/lib/cassandra
      - cassandra-log-3:/var/log/cassandra

  cassandra-4:
    image: cassandra:4.0.5
    container_name: cassandra-4
    hostname: dc-cassandra-4
    mem_limit: 2g
    networks:
      - cassandra
    environment: *cassandra_environment
    volumes:
      - cassandra-data-4:/var/lib/cassandra
      - cassandra-log-4:/var/log/cassandra

Upvotes: 2

Views: 3588

Answers (1)

David Maze
David Maze

Reputation: 158908

You can't access Linux containers by IP address from a Windows host. (...or on a MacOS host, or if you're using a VM-based Docker solution, or if the client isn't on the same host as the containers, or...) Access the containers through their published ports: instead. There's no need to ever look up a container's Docker-internal IP address.

The Docker Desktop documentation notes, under "Known limitations for all platforms":

Per-container IP addressing is not possible: The docker bridge network is not reachable from the host. However if you are a Windows user, it works with Windows containers.

Upvotes: 3

Related Questions