Using this docker-compose.yml.txt with the line ASPNETCORE_ENVIRONMENT: "${VARIABLE:?err}"
I get the error invalid interpolation format for services.web.environment.ASPNETCORE_ENVIRONMENT: "${VARIABLE:?err}". You may need to escape any $ with another $.
using just ${VARIABLE}
or ${VARIABLE:-default}
works as expected.
Documentation https://docs.docker.com/compose/compose-file/#variable-substitution says
Similarly, the following syntax allows you to specify mandatory variables:
${VARIABLE:?err} exits with an error message containing err if VARIABLE is unset or empty in the environment.
${VARIABLE?err} exits with an error message containing err if VARIABLE is unset in the environment.
docker info gives
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.12.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155d4b0101
ID: HEEX:53S5:KDWT:G6UG:L6ST:3COU:JBZ6:ACQP:BMPH:NJR7:P3V2:NMOT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 19
Goroutines: 35
System Time: 2018-02-16T09:54:14.6651446Z
EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Support for this syntax was added in Compose 1.19.0. Please make sure you're using the latest version of the software.
Thanks for your quick answer. What are the requirements if I use docker stack deploy
?
Sidequestion: Is it possible the variable substitution is only supported for strings? I get services.web.ports.0.published must be a integer
when using published: ${WEB_PORT:-8001}
on a windows system
To my knowledge this specific feature hasn't made it into docker stack
yet.
As for your other question, it should work if you use a recent version of Compose (>=1.18)
The Variable Substitution docs make no mention of the mandatory variable syntax not being implemented for docker stack
yet. Other places it specifically states this, like right above that section in the section about .env file
. The docs should probably be updated to reflect this. Is there an issue tracking mandatory variables in docker stack
?
https://github.com/docker/docker.github.io for docs issues
https://github.com/docker/cli for docker stack
issues.
I believe there's an issue in docker/CLI for the mandatory syntax but I'm on mobile right now and can't find it.
Most helpful comment
The Variable Substitution docs make no mention of the mandatory variable syntax not being implemented for
docker stack
yet. Other places it specifically states this, like right above that section in the section about.env file
. The docs should probably be updated to reflect this. Is there an issue tracking mandatory variables indocker stack
?