无法通过curl或Postman访问docker URL [英] Can't access docker url via curl or Postman

查看:509
本文介绍了无法通过curl或Postman访问docker URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下路径在浏览器中访问我的网站:my-dash.docker.localhost:8000

I can access my site in the browser with the following path: my-dash.docker.localhost:8000

我正在尝试编写API端点,并且可以

I am trying to write an API endpoint and can't access the site via Postman or curl.

 curl my-dash.docker.localhost:8000
 curl: (6) Could not resolve host: my-dash.docker.localhost

这是我的docker-compose .yml:

This is my docker-compose.yml:

version: "2"

services:
  mariadb:
    image: wodby/mariadb:10.1-2.1.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: drupal
      MYSQL_USER: drupal
      MYSQL_PASSWORD: drupal
    volumes:
      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.

  php:
    image: wodby/drupal:8-7.1-2.1.2

    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      DB_HOST: mariadb
      DB_USER: drupal
      DB_PASSWORD: drupal
      DB_NAME: drupal
      DB_DRIVER: mysql
      PHP_XDEBUG: 1
      PHP_XDEBUG_DEFAULT_ENABLE: 1
      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0         # This is needed to respect remote.host setting bellow
      PHP_XDEBUG_REMOTE_HOST: "10.254.254.254"  # You will also need to 'sudo ifconfig lo0 alias 10.254.254.254'
    volumes:
     - mydash-sync:/var/www/html:nocopy # Docker-sync for macOS users

  nginx:
    image: wodby/drupal-nginx:8-1.10-2.1.0

    depends_on:
      - php
    environment:
      NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_SERVER_ROOT: /var/www/html/web
    volumes:
     - mydash-sync:/var/www/html:nocopy # Docker-sync for macOS users
    labels:
      - 'traefik.backend=nginx'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:my-dash.docker.localhost'

  solr:
    image: wodby/drupal-solr:8-6.4-2.0.0

    environment:
      SOLR_HEAP: 1024m
    labels:
      - 'traefik.backend=solr'
      - 'traefik.port=8983'
      - 'traefik.frontend.rule=Host:solr.my-dash.docker.localhost'

  mailhog:
    image: mailhog/mailhog
    labels:
      - 'traefik.backend=mailhog'
      - 'traefik.port=8025'
      - 'traefik.frontend.rule=Host:mailhog.my-dash.docker.localhost'

  traefik:
    image: traefik
    command: -c /dev/null --web --docker --logLevel=INFO
    ports:
      - '8000:80'
      - '8080:8080' # Dashboard
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

volumes:
  mydash-sync:
   external: true


推荐答案

您必须编辑 / etc / hosts 文件,才能使计算机解析该名称。将此添加到文件末尾:

You have to edit your /etc/hosts file to get your computer resolving that name. Add this at the end of the file:

127.0.0.1 my-dash.docker.localhost

这篇关于无法通过curl或Postman访问docker URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆