magento Docker容器无法解析.test域在本地主机上运行

sf6xfgos  于 2022-11-12  发布在  Docker
关注(0)|答案(1)|浏览(176)

我有magento运行在一个docker容器使用本教程(https://github.com/markshust/docker-magento)。
docker容器是通过https://magento.test访问的,在浏览器中可以正常工作。我们在magento中有一个脚本试图从容器中连接到https://magento.test,但Could not resolve host: magento.test失败。
基本上主机可以访问magento.test并连接到docker容器。但docker容器不能连接到自己。
我试过在docker-composer.yml中添加额外的主机(见下面),但是没有成功。我猜IP 127.0.0.1是不正确的。

version: "3"

services:
  app:
    image: markoshust/magento-nginx:1.18-8
    ports:
      - "80:8000"
      - "443:8443"
    volumes: &appvolumes
      - ~/.composer:/var/www/.composer:cached
      - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
      - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
      - appdata:/var/www/html
      - sockdata:/sock
      - ssldata:/etc/nginx/certs
    extra_hosts: &appextrahosts
      ## Selenium support, replace "magento.test" with URL of your site
      - "magento.test:127.0.0.1"

  phpfpm:
    image: markoshust/magento-php:7.4-fpm-15
    volumes: *appvolumes
    env_file: env/phpfpm.env
    #extra_hosts: *appextrahosts

  db:
    image: mariadb:10.4
    command:
      --max_allowed_packet=64M
      --optimizer_use_condition_selectivity=1
      --optimizer_switch="rowid_filter=off"
    ports:
      - "3306:3306"
    env_file: env/db.env
    volumes:
      - dbdata:/var/lib/mysql

  redis:
    image: redis:6.2-alpine
    ports:
      - "6379:6379"

  elasticsearch:
    image: markoshust/magento-elasticsearch:7.16-0
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - "discovery.type=single-node"
      ## Set custom heap size to avoid memory errors
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      ## Avoid test failures due to small disks
      ## More info at https://github.com/markshust/docker-magento/issues/488
      - "cluster.routing.allocation.disk.threshold_enabled=false"
      - "index.blocks.read_only_allow_delete"

  rabbitmq:
    image: markoshust/magento-rabbitmq:3.9-0
    ports:
      - "15672:15672"
      - "5672:5672"
    volumes:
      - rabbitmqdata:/var/lib/rabbitmq
    env_file: env/rabbitmq.env

  mailcatcher:
    image: sj26/mailcatcher
    ports:
      - "1080:1080"

  ## Blackfire support, uncomment to enable
  #blackfire:
  #  image: blackfire/blackfire:2
  #  ports:
  #    - "8307"
  #  env_file: env/blackfire.env

  ## Selenium support, uncomment to enable
  #selenium:
  #  image: selenium/standalone-chrome-debug:3.8.1
  #  ports:
  #    - "5900:5900"
  #  extra_hosts: *appextrahosts

volumes:
  appdata:
  dbdata:
  rabbitmqdata:
  sockdata:
  ssldata:

任何帮助将不胜感激,谢谢!

y3bcpkx1

y3bcpkx11#

使用主机网络是否能解决您的问题?

services:
  app:
    image: markoshust/magento-nginx:1.18-8
    network_mode: "host"  # share host network
    ports:
      - "80:8000"
      - "443:8443"
    volumes: &appvolumes
      - ~/.composer:/var/www/.composer:cached
      - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
      - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
      - appdata:/var/www/html
      - sockdata:/sock
      - ssldata:/etc/nginx/certs
    extra_hosts: &appextrahosts
      ## Selenium support, replace "magento.test" with URL of your site
      - "magento.test:127.0.0.1"

相关问题