'Docker Compose Error "TypeError: expected string or buffer" on docker:dind (ports)
I'm triying to setup my containers with docker-compose in a docker container (docker:dind) to make the tests at gitlab ci.
From yesterday to today it has begin to fail on "docker-compose up" and i reduced the error to "ports" segment at service in docker-compose.yml. The simpliest configuration that fails is that:
version: '3':
services:
ubuntu:
image: ubuntu:latest
ports:
- 80:80
I've tried without ports and it works.
The specific error is this:
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
This is the steps to reproduce it:
(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
I don't know if is a problem with python, with docker, docker-compose....
Anybody can help me?
Thanks!
Solution 1:[1]
Error? the problem is most probably(not given) coming from your "docker-compose.yml" file, docker expected a string or bytes-like object but one or more of the values supplied doesn't conform to that format.
Solution - make sure the values supplied to your docker-compose.yml properties document are in the right format. For example one time , i had the wrong spacing in the following property: i.e it looked like;
ports:
- 8000: 8000
but should have been
ports:
- 8000:8000
Notice the spacing of the values supplied.
Solution 2:[2]
I encountered a similar error when working with a NestJS application on macOS.
When I run the command docker-compose up
I get the error:
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
Here's how I solved it
I checked the docker-compose.yml
file and I realized that it did not have the container port specified. This was how the file looked:
version: "3"
services:
web:
image: my-app
build: .
container_name: my-app
ports:
- 8080:
env_file: .env
volumes:
- ".:/app"
All I had to do was to add the container port which was 3001
:
version: "3"
services:
web:
image: my-app
build: .
container_name: my-app
ports:
- 8080:3001
env_file: .env
volumes:
- ".:/app"
That's all
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | bitbuoy |
Solution 2 | Promise Preston |