Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose with two files

I have two docker-compose.yml files in separate folders.

I'd like to run the two of them in the same command, in order for the services from both to be able to talk to each other.

However, when I go to the lowest common path ancestor and try to run docker-compose with both files, here is what happens:

$ docker-compose -f ./api-folder/docker-compose.yml -f ./front-folder/docker-compose.yml up -d
ERROR: build path /projects/front-folder/api either does not exist, is not accessible, or is not a valid URL.

$ docker-compose -f ./front-folder/docker-compose.yml -f ./api-folder/docker-compose.yml up -d
ERROR: build path /projects/api-folder/app either does not exist, is not accessible, or is not a valid URL.

Here are the two docker-compose.yml files:

/projects/front-folder/docker-compose.yml

version: '2'

services:

    app:
        restart: always
        build: ./app
        environment:
            NODE_ENV: 'dev'
        ports:
            - "4400:4400"
        volumes:
            - ./app:/usr/src/app

    nginx:
        restart: always
        build: ./nginx
        volumes:
            - ./logs:/usr/local/var/log/nginx
        links:
            - app
        ports:
            - "80:80"

/projects/api-folder/docker-compose.yml

version: '2'

services:

    api:
        restart: always
        build: ./api
        expose:
            - "4600"
        volumes:
            - ./api:/usr/src/app
            - ./logs:/logs

    nginx:
        restart: always
        build: ./nginx
        volumes:
            - ./logs:/usr/local/var/log/nginx
        links:
            - api
        ports:
            - "81:80"
        networks:
            - hackerz

And the directory structure:

- /projects
    - /front-folder
        - /app
            Dockerfile
        - /nginx
            Dockerfile
        docker-compose.yml
    - /api-folder
        - /api
            Dockerfile
        - /nginx
            Dockerfile
        docker-compose.yml

I'm guessing the problem is with the build paths, but what I don't understand is:

  • Why Docker insists on searching build: ./api in /front-folder or the other way around?
  • How to circumvent this problem and be able to run both files together?
like image 288
Jivan Avatar asked Nov 08 '22 12:11

Jivan


1 Answers

DOCKERFILE Alternate Dockerfile.

Compose uses an alternate file to build with. A build path must also be specified.

service3:
    build:
      context: .
      dockerfile: Dockerfile-alternate

docker compose build giving custom file

like image 52
Jamil Noyda Avatar answered Nov 15 '22 06:11

Jamil Noyda