Docker组成variablesreplace做一个数字
我想在docker-compose.yml
使用variablesreplace来设置CPU的数量。
有了这个撰写文件:
test.yml
version: "2.2" services: neo4j: image: neo4j:3.2 cpus: ${MAX_CPUS}
由此脚本运行:
test.sh
#!/bin/sh export MAX_CPUS=4 docker-compose -f test.yml up -d
我得到这个错误:
$ ./test.sh ERROR: The Compose file './test.yml' is invalid because: services.neo4j.cpus contains an invalid type, it should be a number
该variables正在被正确读取。 如果使用这个组成文件
version: "2.2" services: neo4j: image: neo4j:3.2 #cpus: ${MAX_CPUS} volumes: - ${MAX_CPUS}:/foo
那么我得到一个使用replace值的错误:
ERROR: Named volume "4:/foo:rw" is used in service "neo4j" but no declaration was found in the volumes section.
看起来,variablesreplace被解释为一个string,即使该值是一个数字。
有没有办法强制它的数字,假设是这个问题?
我使用docker-machine在Mac OS X上运行。
$ docker-compose --version docker-compose version 1.17.1, build 6d101fb $ docker-machine --version docker-machine version 0.13.0, build 9ba6da9
我search了Docker Compose GitHub问题,并find了https://github.com/docker/compose/issues/2730 。 听起来和你的问题非常相似。 它在pull请求https://github.com/docker/compose/pull/5291中被修正,其中为内插值添加了一个types转换器。 它似乎支持每行的cpus
选项https://github.com/docker/compose/pull/5291/files#diff-b2372f2a81cc5911e04cc7df7d68675bR148 。
但是,如果我们看一下在https://github.com/docker/compose/pull/5291/files#diff-b2372f2a81cc5911e04cc7df7d68675bR139上匹配转换的正则expression式,我们可以看到它是^0[0-9]+$
。 这个正则expression式不匹配单个数字。 但它应该匹配01
。
所以,听起来很愚蠢,你可以尝试将数字改为04
而不是4
吗?