How to configure a Build Arg in App Specification for Docker-based service

Posted October 18, 2020 2.2k views
DockerDigitalOcean App Platform

Dear support, is there a way to configure one or more --build-arg values for a Docker-based service in the App Platform?

At the Docker build time, we pass arguments to fine-tune nginx configuration files. We use different Build Arg values for our development, staging, and production environments.

Also, it is not clear whether build_command happens after docker build, or is it actually the way to customize how docker build runs? Could you give some examples of using build_command with Dockerfiles?

Many thanks!

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

@ReWild 👋

The way to accomplish this today would be to pass in build-time environment variables. If you’re creating envs through the UI, then they’re by default build-and-run-time variables. If creating via raw app spec and doctl, then you can choose one or both using the scope field. We don’t currently support passing --build-args directly, but this is a good idea that we’ll consider adding to the product — your feedback here helps.

An example of an app spec with build-time environment variables might look like this:

name: sample-dockerfile-static
- name: site
    repo: digitalocean/sample-dockerfile-static
    branch: master
  - key: API_URL
    scope: BUILD_TIME

Hopefully that’s a sufficient workaround in the meantime. Stay tuned to our product release notes for updates on this and other features.

Thanks for using the App Platform, and happy coding!

  • Thanks @snormoredo. Apparently, this does not help, as host environment variables are not visible during the build time. For example, in Dockerfile:


    ENV_APP_HOST, which is a host environment variable, is not visible during the build time.

    For example, when building the container locally: docker build ...

    The Dockerfile can’t see the ENV_APP_HOST – it is empty. I expect the same to happen when the App Platform will build my Dockerfile. Even if I set an environment variable in my App Spec, it won’t be seen during the build time.

    So what would be a working workaround here?

    Without a workaround, we won’t be able to use the same nginx Dockerfile for two separate Apps running under two separate domains, e.g. and We will have to maintain two separate Dockerfiles, each hardcoding the domain name. Please advise.