Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api not accessible once i changed the domain names in docker compose file #1651

Closed
virkse opened this issue Sep 18, 2020 · 2 comments
Closed

Comments

@virkse
Copy link

virkse commented Sep 18, 2020

I just changed the domain names in docker-compose.yml file so api is not accessible. Also i didn't get information how to change the domain. Please help me.

My docker compose file, I just changed http://api to https://api-platform.local
Also i put the https://api-platform.local in /etc/hosts
When i run the logs from container using docker-compose logs -f the following message return.
http: proxy error: dial tcp: lookup api-platform.local on 127.0.0.11:53: no such host" symfony api platform

version: '3.4'

x-cache-from:
  - &api-cache-from
    cache_from:
      - ${NGINX_IMAGE:-quay.io/api-platform/nginx}
      - ${PHP_IMAGE:-quay.io/api-platform/php}

services:
  php:
    build:
      context: ./api
      target: api_platform_php
      <<: *api-cache-from
    image: ${PHP_IMAGE:-quay.io/api-platform/php}
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    depends_on:
      - db
      - dev-tls
    volumes:
      - ./api:/srv/api:rw,cached
      - ./api/docker/php/conf.d/api-platform.dev.ini:/usr/local/etc/php/conf.d/api-platform.ini
      # if you develop on Linux, you may use a bind-mounted host directory instead
      # - ./api/var:/srv/api/var:rw
      - dev-certs:/certs:ro,nocopy

  api:
    build:
      context: ./api
      target: api_platform_nginx
      <<: *api-cache-from
    image: ${NGINX_IMAGE:-quay.io/api-platform/nginx}
    depends_on:
      - php
    volumes:
      - ./api/public:/srv/api/public:ro

  vulcain:
    image: dunglas/vulcain
    environment:
      - CERT_FILE=/certs/localhost.crt
      - KEY_FILE=/certs/localhost.key
      - UPSTREAM=https://api-platform.local
    depends_on:
      - api
      - dev-tls
    volumes:
      - dev-certs:/certs:ro,nocopy
    ports:
      - target: 443
        published: 8443
        protocol: tcp

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB=api
      - POSTGRES_PASSWORD=!ChangeMe!
      - POSTGRES_USER=api-platform
    volumes:
      - db-data:/var/lib/postgresql/data:rw
      # you may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./api/docker/db/data:/var/lib/postgresql/data:rw
    ports:
      - target: 5432
        published: 5432
        protocol: tcp

  mercure:
    image: dunglas/mercure
    environment:
      - ALLOW_ANONYMOUS=1
      - CERT_FILE=/certs/localhost.crt
      - CORS_ALLOWED_ORIGINS=*
      - DEMO=1
      - JWT_KEY=!ChangeMe!
      - KEY_FILE=/certs/localhost.key
      - PUBLISH_ALLOWED_ORIGINS=https://api-platform.local:1337 # required for publishing from the demo page
    depends_on:
      - dev-tls
    volumes:
      - dev-certs:/certs:ro,nocopy
    ports:
      - target: 443
        published: 1337
        protocol: tcp

  client:
    build:
      context: ./client
      target: api_platform_client_development
      cache_from:
        - ${CLIENT_IMAGE:-quay.io/api-platform/client}
    image: ${CLIENT_IMAGE:-quay.io/api-platform/client}
    tty: true # https://github.com/facebook/create-react-app/issues/8688
    environment:
      - API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT=https://api-platform.local
      - API_PLATFORM_CLIENT_GENERATOR_OUTPUT=src
    depends_on:
      - dev-tls
    volumes:
      - ./client:/usr/src/client:rw,cached
      - dev-certs:/usr/src/client/node_modules/webpack-dev-server/ssl:rw,nocopy
    ports:
      - target: 3000
        published: 443
        protocol: tcp

  admin:
    build:
      context: ./admin
      target: api_platform_admin_development
      cache_from:
        - ${ADMIN_IMAGE:-quay.io/api-platform/admin}
    image: ${ADMIN_IMAGE:-quay.io/api-platform/admin}
    tty: true # https://github.com/facebook/create-react-app/issues/8688
    depends_on:
      - dev-tls
    volumes:
      - ./admin:/usr/src/admin:rw,cached
      - dev-certs:/usr/src/admin/node_modules/webpack-dev-server/ssl:rw,nocopy
    ports:
      - target: 3000
        published: 444
        protocol: tcp

  dev-tls:
    build:
      context: ./docker/dev-tls
    volumes:
      - dev-certs:/certs:rw
    ports:
      - target: 80
        published: 80
        protocol: tcp

volumes:
  db-data: {}
  dev-certs: {}
@Ledalys
Copy link

Ledalys commented Sep 21, 2020

Hi,

From the doc :

When you run docker-compose up, the following happens:
1 - A network called myapp_default is created.
2 - A container is created using web’s configuration. It joins the network myapp_default under the name web.
3 - A container is created using db’s configuration. It joins the network myapp_default under the name db.

Each container can now look up the hostname web or db and get back the appropriate container’s IP address. For example, web’s application code could connect to the URL postgres://db:5432 and start using the Postgres database.

You are not supposed to edit http://api, this is the hostname used by your containers (vulcain and the client generator) to reach your container called "api" inside their network. You will use https://api-platform.local to reach vulcain and vulcain will use http://api to reach api.

To change the domain from /etc/hosts you need to

  • map it to the IP of the machine hosting docker (localhost or a virtual machine IP or whatever but not your container) :
127.0.0.1 api-platform.local
  • edit CORS_ALLOW_ORIGIN and TRUSTED_HOSTS in api/.env (or create api/.env.local)
TRUSTED_HOSTS='^(api-platform.local|localhost|api)$'
CORS_ALLOW_ORIGIN=^https?://(api-platform.local|localhost|127\.0\.0\.1)(:[0-9]+)?$
  • edit REACT_APP_API_ENTRYPOINT in admin/.env and client/.env
REACT_APP_API_ENTRYPOINT=https://api-platform.local:8443
  • edit mercure.PUBLISH_ALLOWED_ORIGINS from docker-compose.yml
PUBLISH_ALLOWED_ORIGINS=https://api-platform.local:1337
  • Build and up using docker-compose.

Then you can go to https://api-platform.local:8443

@virkse
Copy link
Author

virkse commented Sep 22, 2020

@Ledalys It was really a life saving reply. I clears my understandings. Thank you very much to help me out.

@virkse virkse closed this as completed Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants