Run docker-compose from bash script file

13,629

Solution 1

You can call them separately:

#!/bin/bash
docker-compose -f docker-compose.yml up -d
docker-compose -f docker-compose-mongo.yml up -d

Or combine both nginx and mongo services in the same docker-compose.yml.

Solution 2

You can have multiple yml files on the same command:

docker-compose -f docker-compose.yml -f docker-compose-mongo.yml up -d
Share:
13,629
Parampreet Sekhon
Author by

Parampreet Sekhon

Updated on June 04, 2022

Comments

  • Parampreet Sekhon
    Parampreet Sekhon almost 2 years

    I am new to scripting and require some assistance. I am building docker container using YML file. I have YML code written to automate my web server (docker-compose.yml) and database server(docker-compose-mongo.yml).

    Now I want to build a bash script that will call for both the yml files and run together.

    I was wondering what commands do I need to type within my shell script to call for these two yml files and run them together. I initially just used

    #!/bin/bash
    run docker-compose.yml
    

    But the above code didn't work.

    Ps. below is my yml file for the web server

    version: "3"
    services:
      web:
        image: nginx:latest
        deploy:
          replicas: 5
          resources:
            limits:
              cpus: "0.2"
              memory: 330M
          restart_policy:
            condition: on-failure
        ports:
          - "80:80"
        # networks:
          # - webnet
    # networks:
      # webnet: