kRicha
kRicha

Reputation: 837

docker with two separated php-services on one php container

i have docker-compose.yml with content:

nginx:
build: ./nginx/
ports:
    - 80:80
links:
    - php
volumes:
    - ./code:/var/www/
    - ./nginx/site.local.conf:/etc/nginx/conf.d/site.local.conf
    - ./nginx/api.local.conf:/etc/nginx/conf.d/api.local.conf
php:
    build: ./php/
    expose:
        - 9000
    volumes:
        - ./code/cms:/var/www/site
        - ./code/www:/var/www/api

on my local machine i can get all hosts separate site.local & api.local

but i have one problem and can't resolve it:

there in php requests from site.local to api.local, so i get errors like this:

cURL error 6: Could not resolve host: api.local

could anybody help me? thanks.

Upvotes: 1

Views: 445

Answers (1)

kRicha
kRicha

Reputation: 837

I have an answer on my question!

version: "2"

networks:
    lan_0:
        driver: bridge
        ipam:
            driver: default
            config:
                - subnet: 172.19.0.0/24
                  gateway: 172.19.0.21

services:
    nginx:
        build: ./nginx/
        ports:
            - 80:80
            - 443:443
        links:
            - php
        volumes:
            - ./code:/var/www/
        networks:
            lan_0:
                ipv4_address: 172.19.0.22
    php:
        build: ./php/
        expose:
            - 9000
        volumes:
            - ./code:/var/www
        extra_hosts:
            - "api.local:172.19.0.22"
            - "site.local:172.19.0.22"
        networks:
            lan_0:
                ipv4_address: 172.19.0.23

That is example, how to communicate two web-application in one php-container.

Upvotes: 2

Related Questions