Docker编写错误“类型错误:在docker:dind(ports)上需要字符串或缓冲区”

vxqlmq5t  于 2023-02-03  发布在  Docker
关注(0)|答案(2)|浏览(119)

我正在尝试在一个docker container(docker:dind)中使用docker-compose来设置我的container,以便在gitlab ci上进行测试。
从昨天到今天,"docker-compose up"开始出现故障,我将错误减少到docker-compose.yml中服务的"ports"段。出现故障的最简单配置是:

version: '3':
services:
        ubuntu:
                image: ubuntu:latest
                ports:
                        - 80:80

我试过不带端口,它工作正常。
具体错误如下:

ERROR: for ubuntu  expected string or buffer
Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 68, in main
    command()
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 118, in perform_command
    handler(command, command_options)
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 926, in up
    scale_override=parse_scale_args(options['--scale']),
  File "/usr/lib/python2.7/site-packages/compose/project.py", line 424, in up
    get_deps
  File "/usr/lib/python2.7/site-packages/compose/parallel.py", line 69, in parallel_execute
    raise error_to_reraise
TypeError: expected string or buffer

这是重现它的步骤:

(at your machine)
~ docker run --privileged -d docker:stable-dind
~ docker exec -ti *CONTAINER_ID* sh

(inside of the docker container)

~ apk add --no-cache py-pip vim
~ pip install docker-compose

(here edit a docker-compose.yml and paste the up yaml code)

~ docker-compose up

我不知道是不是python、docker、docker-compose的问题。
有人能帮我吗?
谢谢!

hc2pp10m

hc2pp10m1#

**错误?**问题很可能(未给出)来自您的“docker-compose.yml”文件,docker需要一个字符串或类似字节的对象,但提供的一个或多个值不符合该格式。
解决方案-确保提供给docker-compose.yml属性文档的值格式正确。例如,有一次,我在以下属性中使用了错误的间距:即它看起来像;

ports:
   - 8000: 8000

但应该是

ports:
   - 8000:8000

请注意所提供值的间距。

zte4gxcn

zte4gxcn2#

我在macOS上使用NestJS应用程序时遇到了类似的错误。
当我运行命令docker-compose up时,我得到错误:

Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 200, in perform_command
  File "compose/cli/command.py", line 60, in project_from_options
  File "compose/cli/command.py", line 148, in get_project
  File "compose/config/config.py", line 423, in load
  File "compose/config/config.py", line 424, in <listcomp>
  File "compose/config/config.py", line 626, in process_config_file
  File "compose/config/validation.py", line 474, in validate_against_config_schema
  File "compose/config/validation.py", line 537, in handle_errors
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 282, in properties
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 23, in patternProperties
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 263, in ref
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 282, in properties
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_legacy_validators.py", line 55, in items_draft3_draft4
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 337, in oneOf
  File "jsonschema/validators.py", line 344, in descend
  File "jsonschema/validators.py", line 328, in iter_errors
  File "jsonschema/_validators.py", line 45, in additionalProperties
  File "jsonschema/_utils.py", line 98, in find_additional_properties
  File "/Users/administrator/jenkins/workspace/dsg_compose_1.29.2/build/toolchain/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 201, in search
TypeError: expected string or bytes-like object
[21470] Failed to execute script docker-compose

"我是这么解决的"
我检查了docker-compose.yml文件,发现它没有指定container port

version: "3"
services:
  web:
    image: my-app
    build: .
    container_name: my-app
    ports:
      - 8080:
    env_file: .env
    volumes:
      - ".:/app"

我所要做的就是添加容器端口,即3001

version: "3"
services:
  web:
    image: my-app
    build: .
    container_name: my-app
    ports:
      - 8080:3001
    env_file: .env
    volumes:
      - ".:/app"

相关问题