How to set Docker-compose arguments in console?

My Docker containers will be set up through a bash script.

In my docker-compose.yml file (which is called through docker-compose up inside the bash file) I have a few arguments:

  • Apply NetEM WAN delay on a docker container interface
  • AWS EB, Play Framework and Docker: Application Already running
  • Docker calling unit tests
  • Prevent skip in docker-compose
  • How to get Container Id of Docker in Jenkins
  • Elastic search with docker does not start
  • version: "2"
    services:
        nginx:
            build: ./Dockerfiles/wordpress-nginx
            expose:
                - "80"
            depends_on:
                - fpm
            links:
                - fpm
            container_name: wordpress-nginx
            args:
                - site_title=Example
                - admin_email=test@test.co
                - site_url=www.testcase001.com
                - admin_user=admin
                - admin_pass=qwerty
                - ssl_domain=www.testcase001.com
                - dbname=testcase
                - dbuser=testcase
                - dbpass=testcase
                - dbhost=testcase
        fpm:
            build: ./Dockerfiles/php-fpm
            expose:
                - "9000"
            container_name: fpm
    

    Now my question is this:

    How can I set the arguments from the command line?

    For example:
    I want to set the site_title argument: docker-compose up --something-to-set-the-site_title-argument

  • docker COPY .env file fail
  • Building from one image and adding dependency to another
  • docker build with --build-arg with multiple variables
  • Parse a string to array in node.js
  • How do I copy the files from one directory to another using a dockerfile?
  • Have to set up eval $(dinghy env) everytime. Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • One Solution collect form web for “How to set Docker-compose arguments in console?”

    You can use environment variables in your docker-compose.yaml file, e.g.:

    args:
      - site_title: $SITE_TITLE
    

    In your Bash script, you can then set the title environment variable like this:

    #!/bin/bash
    
    SITE_TITLE="My new title"
    
    docker-compose up -d
    

    The $SITE_TITLE environment variable should then be used in your compose configuration.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.