如何验证我的docker-compose.yml?
How to verify my docker-compose.yml?
我正在使用 docker-compose 设置容器堆栈。然而 运行
docker-compose up
我收到一条相当神秘的错误消息:
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 9, in <module>
load_entry_point('docker-compose==1.4.2', 'console_scripts', 'docker-compose')()
File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 39, in main
command.sys_dispatch()
File "/usr/local/lib/python2.7/dist-packages/compose/cli/docopt_command.py", line 21, in sys_dispatch
self.dispatch(sys.argv[1:], None)
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 27, in dispatch
super(Command, self).dispatch(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/compose/cli/docopt_command.py", line 24, in dispatch
self.perform_command(*self.parse(argv, global_options))
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 57, in perform_command
verbose=options.get('--verbose'))
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 78, in get_project
config.load(config_details),
File "/usr/local/lib/python2.7/dist-packages/compose/config.py", line 138, in load
for service_name, service_dict in list(dictionary.items()):
AttributeError: 'NoneType' object has no attribute 'items'
如何调试?我已经检查过 yml 是有效的,但它不起作用。
我忘记保存我的 docker-compose.yml
,所以它是空的。
我在 this issue about making the error message better 中偶然发现了描述行为的解决方案。
如果 docker-compose.yml
根本不存在,就会收到一条好消息:
Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml, fig.yml, fig.yaml
anounced on the docker-compose's issue 列出在即将发布的 1.5 版本中会有更好的错误消息:
Top level object needs to be a dictionary. Check your .yml file that
you have defined a service at the top level.
从版本 1.7.1 开始,指示您的文件为空的错误消息如下:
ERROR: Top level object in './docker-compose.yml' needs to be an
object not '<type 'NoneType'>'.
鉴于最新版本,错误消息非常简单:
$ docker -v
Docker version 19.03.13, build 4484c46d9d
$ docker build .
failed to solve with frontend dockerfile.v0: failed to create LLB definition: the Dockerfile cannot be empty
因此,为了便于使用,请考虑升级您的 docker 引擎。
我正在使用 docker-compose 设置容器堆栈。然而 运行
docker-compose up
我收到一条相当神秘的错误消息:
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 9, in <module>
load_entry_point('docker-compose==1.4.2', 'console_scripts', 'docker-compose')()
File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 39, in main
command.sys_dispatch()
File "/usr/local/lib/python2.7/dist-packages/compose/cli/docopt_command.py", line 21, in sys_dispatch
self.dispatch(sys.argv[1:], None)
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 27, in dispatch
super(Command, self).dispatch(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/compose/cli/docopt_command.py", line 24, in dispatch
self.perform_command(*self.parse(argv, global_options))
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 57, in perform_command
verbose=options.get('--verbose'))
File "/usr/local/lib/python2.7/dist-packages/compose/cli/command.py", line 78, in get_project
config.load(config_details),
File "/usr/local/lib/python2.7/dist-packages/compose/config.py", line 138, in load
for service_name, service_dict in list(dictionary.items()):
AttributeError: 'NoneType' object has no attribute 'items'
如何调试?我已经检查过 yml 是有效的,但它不起作用。
我忘记保存我的 docker-compose.yml
,所以它是空的。
我在 this issue about making the error message better 中偶然发现了描述行为的解决方案。
如果 docker-compose.yml
根本不存在,就会收到一条好消息:
Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml, fig.yml, fig.yaml
anounced on the docker-compose's issue 列出在即将发布的 1.5 版本中会有更好的错误消息:
Top level object needs to be a dictionary. Check your .yml file that you have defined a service at the top level.
从版本 1.7.1 开始,指示您的文件为空的错误消息如下:
ERROR: Top level object in './docker-compose.yml' needs to be an object not '<type 'NoneType'>'.
鉴于最新版本,错误消息非常简单:
$ docker -v
Docker version 19.03.13, build 4484c46d9d
$ docker build .
failed to solve with frontend dockerfile.v0: failed to create LLB definition: the Dockerfile cannot be empty
因此,为了便于使用,请考虑升级您的 docker 引擎。