Answer the question
In order to leave comments, you need to log in
How to properly configure docker containers for curl to work correctly in php?
There is docker-compose , in which nginx and php are in separate containers
version: '3'
services:
php:
build:
context: ./docker/php
ports:
- ${PORT_PHP}:9000
volumes:
- ${PATH_PROJECT}:/srv/www/promo
- ${PATH_STATIC}:/srv/www/promo-static
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./docker/php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
environment:
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
nginx:
image: nginx:1.13.8
ports:
- ${PORT_NGINX}:80
volumes:
- ${PATH_PROJECT}:/srv/www/promo
- ${PATH_STATIC}:/srv/www/promo-static
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
environment:
NGINX_HOST: ${NGINX_HOST}
PORT_PHP: ${PORT_PHP}
mysql:
image: mysql:5.7
ports:
- ${PORT_MYSQL}:3306
depends_on:
- php
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
127.0.0.1 promo.mdtest.org
...
PORT_PHP=9002
PORT_NGINX=8002
PORT_MYSQL=3308
Answer the question
In order to leave comments, you need to log in
It's not about docker-compose.
When you open the promo.mdtest.org site page through a browser, you use address resolution on the host.
When you open the promo.mdtest.org site page through the php container, you use address resolution in the php container.
If you want to get the same results, you need to have access to this site inside the container too.
Because docker-compose creates a network for all the specified containers on startup, then you can access this site inside the container, like this:curl nginx -H 'Host: promo.mdtest.org'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question