DEV Community

Discussion on: Create API Rest with Laravel 7.X Passport Authentication And Implement Refresh Token (Part 1)

Collapse
 
azibom profile image
Mohammad Reza

Hi, i dockerized my project and that is my container name, you should replace it with "localhost/oauth/token" or "localhost:8080/oauth/token" (if you are using "php artisan serv") and you don't need to set up anything

Collapse
 
riosdelibertad profile image
Rios de libertad • Edited

I was looking in documentation for the problem and found that having php and the web server (nginx) in different docker containers don't communicate by curl because php makes a call to localhost and not to the nginx container, for that reason it can't solve the url.

The solution is to put in the docker-compose.yml file in the container with php

extra_hosts:
- "url-container:172.18.0.3"

url-container: is the url our project.
172.18.0.3: The ip of the web server container (nginx in my case).

Change nginx-service to the name of the container where you have the web server.

I had to reboot everything to make it work, even my machine

My docker-compose.yml

version: '3.5'

networks:
servicesnet:
name: networkservices
driver: bridge

services:
nginx:
image: nginx:latest
container_name: nginx-service
ports:
- "80:80"
- "443:443"
networks:
- servicesnet
volumes:
- ../../mywebs:/var/www/localhost/htdocs
- ./pages/default:/var/www/localhost/htdocs/default
- ./nginx/config:/etc/nginx
- ./nginx/logs:/var/log/nginx
- ./nginx/certificates:/sites/ssl
links:
- php
php:
image: lep-alpine_php
container_name: php-service
volumes:
- ../../mywebs:/var/www/localhost/htdocs
- ./pages/default:/var/www/localhost/htdocs/default
- ./php:/etc/php7
networks:
- servicesnet
extra_hosts:
- "url-container:172.18.0.3"