通过本地网络共享 Docker 容器并从另一台主机访问它

Share Docker container through local network and access to it from an another host

我尝试通过我的本地网络共享一个容器,以便从同一网络上的另一台机器访问该容器。我已关注 tihs tutorial(第 "With macvlan devices" 节),我成功地共享了一个简单的 Web 容器并从另一台主机访问。

但是我要共享的容器稍微复杂一些,因为他通过主机上的内部网络与主机上的其他容器通信。

我尝试绑定在 docker-compose 中创建的现有容器,但我无法访问它。你能帮帮我吗,或者如果可以请告诉我哪里错了?

这是我的 docker-撰写 :

version: "2"
services:
  baseimage:
    container_name: baseimage
    image: base
    build:
      context: ./
      dockerfile: Dockerfile.base
  web:
    container_name: web
    image: web
    env_file:
      - .env
      context: ./
      dockerfile: Dockerfile.web
    extra_hosts:
      - dev.api.exemple.com:127.0.0.1
      - dev.admin.exemple.com:127.0.0.1
      - dev.www.exemple.com:127.0.0.1
    ports:
     - 80:80
     - 443:443
    volumes:
     - ./code:/ass
     - /var/run/docker.sock:/var/run/docker.sock
    tty: true
    dns:
      - 8.8.8.8
      - 8.8.4.4
    links:
      - mysql
      - redis
      - elasticsearch
      - baseimage
    networks:
      devbox:
        ipv4_address: 172.20.0.2
  cron:
    container_name: cron
    image: cron
    build:
      context: ./
      dockerfile: Dockerfile.cron
    volumes:
     - ./code:/ass
    tty: true
    dns:
      - 8.8.8.8
      - 8.8.4.4
    links:
      - web:dev.api.exemple.com
      - mysql
      - redis
      - elasticsearch
      - baseimage
    networks:
      devbox:
        ipv4_address: 172.20.0.3
  mysql:
    container_name: mysql
    image: mysql:5.6
    ports:
      - 3306:3306
    networks:
      devbox:
        ipv4_address: 172.20.0.4
  redis:
    container_name: redis
    image: redis:3.2.4
    ports:
      - 6379:6379
    networks:
      devbox:
        ipv4_address: 172.20.0.5
  elasticsearch:
    container_name: elastic
    image: elasticsearch:2.3.4
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - ./es_data:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      devbox:
        ipv4_address: 172.20.0.6
  chromedriver:
    container_name: chromedriver
    image: robcherry/docker-chromedriver:latest
    privileged: true
    ports:
      - 4444:4444
    environment:
      - CHROMEDRIVER_WHITELISTED_IPS='172.20.0.2'
      - CHROMEDRIVER_URL_BASE='wd/hub'
      - CHROMEDRIVER_EXTRA_ARGS='--ignore-certificate-errors'
    networks:
      devbox:
        ipv4_address: 172.20.0.7
    links:
      - web:dev.www.exemple.com
networks:
  devbox:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
        - subnet: 172.20.0.0/16
          gateway: 172.20.0.1

创建一个 external 网络,将 external 网络和 devbox 网络分配给 web。然后,Web 将 public 只能通过 external 网络 public IP 地址访问,并使用 devbox 网络与内部服务通信。

将post工作示例尽快