Not sure if it's a bug or a new feature, but ... Since 1.27.0+, docker-compose config returns only the major digit from version field.
Output of docker-compose version
docker-compose version 1.27.0, build unknown
docker-py version: 4.3.1
CPython version: 3.7.9
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
Output of docker version
Docker version 19.03.12, build 48a66213fe
version: '3.7'
Run docker-compose config.
Check the output.
services: {}
version: '3'
services: {}
version: '3.7'
No error
Ubuntu 18.04, docker-compose 1.27.0 installed from pip on Python 3.7.9.
Hello @Toilal!
Thank you for your report!
Actually that's because since the latest compose-spec the version is not important anymore, since it's a merge of all the previous ones. We are also thinking about removing this from docker-compose config since it's not important anymore.
This is actually a problem for docker swarm / services like Play with docker at the moment because only using '3' throws errors for ports and volume config
ERROR: The Compose file '/var/run/pwd/uploads/stack.yml' is invalid because:
services.web.ports is invalid: Invalid port "{'published': 80, 'target': 80}", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]
services.web.ports contains an invalid type, it should be a string, or a number
services.web.volumes contains an invalid type, it should be a string
services.web.volumes contains an invalid type, it should be a string
See
https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/t3easy/docker-typo3/7835138e9ae4e36f21d4cb644e2c93b2e52335df/.docker/pwd/stack.yml
vs:
https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/t3easy/docker-typo3/28e4e22e43354fb2e77cdeddb760c12c4ba28866/.docker/pwd/stack.yml
Ok. We will make it a 3.9 then. Does it work for you?
docker 19.03 can't stack-deploy version 3.9. You could output the version that was used in the input.
IIRC, version "3" is interpreted as "3.0", which would explain the errors mentioned above.
docker-compose 1.27.0, docker 19.03.8
Confirming @sgammill theory above. I'm using docker-compose config as a pre-processor as described here to work around stack-deploy being unable to interpolate values from an .env file. The resulting output uses long ports syntax and does not specify a minor version for the compose file, so docker assumes version 3.0, throwing the error services.core.ports.0 must be a string or number
Relevant section of the output:
services:
core:
command:
...
image: ...
ports:
- published: 19999
target: 19999
version: '3'
+1 docker-compose config should output the same version that was used in the input.
Well, we will then just propagate the version on the file, but you could just use something simpler for this environment variable interpolation. Like https://github.com/a8m/envsubst for example