1

I have a command to be executed in my docker-compose.yml with docker-compose up --build -d:

(...)
command: certonly --webroot -w /var/www/certbot \
         -d test.apps.example.com

but I would like to have something like this:

(...)
command: certonly --webroot -w /var/www/certbot \
         -d ${arg}.example.com

and: docker-compose up --build -d "test.apps"

Any idea how I can achieve this?

supersize
  • 13,764
  • 18
  • 74
  • 133

2 Answers2

0

Looks like you are looking for build args:

https://docs.docker.com/compose/reference/build/

Usage: docker-compose build [options] [--build-arg key=val...] [SERVICE...]

Options:
--compress              Compress the build context using gzip.
--force-rm              Always remove intermediate containers.
--no-cache              Do not use cache when building the image.
--pull                  Always attempt to pull a newer version of the image.
-m, --memory MEM        Sets memory limit for the build container.
--build-arg key=val     Set build-time variables for services.
--parallel              Build images in parallel.

and How to pass arguments within docker-compose?

JamalMcCrackin
  • 620
  • 10
  • 15
0

Docker-compose supports variable substitution. It reads env from your working shell. https://docs.docker.com/compose/compose-file/#variable-substitution

In your compose file:

command: certonly --webroot -w /var/www/certbot \
         -d ${SUB_DOMAIN}.example.com

In you shell, export the variable:

export SUB_DOMAIN=test.apps

then

docker-compose up --build
Siyu
  • 11,187
  • 4
  • 43
  • 55
  • This is it, what I was actually looking for was `docker-compose run -e VAR=anything` but it is essentially the same but inline. – supersize Jan 06 '19 at 13:46