compose: docker-compose up fails with 'expected string or buffer' when specifying ports

$ cat docker-compose.yml
version: "3"
services:
  bug:
    image: hello-world
    ports:
      - "8000:8000"
$ docker-compose up
ERROR: for bug  expected string or buffer
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 68, in main
    command()
  File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 118, in perform_command
    handler(command, command_options)
  File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 926, in up
    scale_override=parse_scale_args(options['--scale']),
  File "/usr/local/lib/python2.7/dist-packages/compose/project.py", line 424, in up
    get_deps
  File "/usr/local/lib/python2.7/dist-packages/compose/parallel.py", line 69, in parallel_execute
    raise error_to_reraise
TypeError: expected string or buffer
$ docker-compose --version
docker-compose version 1.14.0, build c7bdf9e
$ docker --version
Docker version 17.05.0-ce, build 89658be
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.04
Release:	17.04
Codename:	zesty

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 22
  • Comments: 27

Most upvoted comments

Thanks for the reports everyone, I’m currently working on a 2.4.2 release of the Python SDK that should fix this particular issue. It should be available in the next few hours.

Can confirm the downgrade of docker and docker-compose resolves the problem. This issue caused all our docker deployments on circle to fail.

in my case I changed ports to integers 🍩 and this fixed my issue

ports:
      - 8000:8000

Same issue here via python3

ERROR: for consul  expected string or bytes-like object
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/compose/cli/main.py", line 68, in main
    command()
  File "/usr/local/lib/python3.5/dist-packages/compose/cli/main.py", line 118, in perform_command
    handler(command, command_options)
  File "/usr/local/lib/python3.5/dist-packages/compose/cli/main.py", line 926, in up
    scale_override=parse_scale_args(options['--scale']),
  File "/usr/local/lib/python3.5/dist-packages/compose/project.py", line 424, in up
    get_deps
  File "/usr/local/lib/python3.5/dist-packages/compose/parallel.py", line 69, in parallel_execute
    raise error_to_reraise
  File "/usr/local/lib/python3.5/dist-packages/compose/parallel.py", line 167, in producer
    result = func(obj)
  File "/usr/local/lib/python3.5/dist-packages/compose/project.py", line 410, in do
    rescale=rescale
  File "/usr/local/lib/python3.5/dist-packages/compose/service.py", line 460, in execute_convergence_plan
    self.show_scale_warnings(scale)
  File "/usr/local/lib/python3.5/dist-packages/compose/service.py", line 205, in show_scale_warnings
    if self.specifies_host_port() and desired_num > 1:
  File "/usr/local/lib/python3.5/dist-packages/compose/service.py", line 983, in specifies_host_port
    return any(has_host_port(binding) for binding in self.options.get('ports', []))
  File "/usr/local/lib/python3.5/dist-packages/compose/service.py", line 983, in <genexpr>
    return any(has_host_port(binding) for binding in self.options.get('ports', []))
  File "/usr/local/lib/python3.5/dist-packages/compose/service.py", line 963, in has_host_port
    _, external_bindings = split_port(binding)
  File "/usr/local/lib/python3.5/dist-packages/docker/utils/ports.py", line 57, in split_port
    match = PORT_SPEC.match(port)
TypeError: expected string or bytes-like object

Worked yesterday morning, started failing this morning, here is a consul snippet with the port defined (This produces the error above).

  consul:
    image: consul:0.8.3
    network_mode: "host"
    restart: always
    command: "agent -server -ui -bootstrap-expect=1 -client=0.0.0.0 -recursor=8.8.8.8 -recursor=8.8.4.4 -dns-port=53 
    environment:
      CONSUL_BIND_INTERFACE: eth0
      CONSUL_LOCAL_CONFIG: '{"dns_config":{"allow_stale":false} }'
      CONSUL_ALLOW_PRIVILEGED_PORTS: "true"
    volumes:
      - "/path/to/vol:/consul/data"
    ports:
      - "8300:8300/tcp"

If we remove the ports section consul starts.

Python 3 Modules

docker==2.4.0
docker-compose==1.14.0
docker-pycreds==0.2.1
dockerpty==0.4.1

Work around: docker was updated to 2.4.0 15 hours ago. I reverted back to docker 2.3.0 and it worked.

pip uninstall docker
pip uninstall docker-compose

pip install docker==2.3.0
pip install docker-compose==1.14.0

Works^^

NB: Same error for docker-compose 1.13.0. 1.12.0 seems to work.

sudo pip install docker-compose==1.12.0

For anyone affected, please pip install -U docker==2.4.2. Let me know if there are any issues still.

Downgrading the docker python library worked for me as well:

pip install --force docker==2.3.0

Not seeing the problem after a new upgrade on arch, have been working for a couple of days now.

Just a follow up.

I’ve tried to install a new virtualenv and now it is working. Sorry for the false alert.

It seems the culprit on my system was python-docker 2.4, I downgraded to 2.3.0 and Docker / Docker-compose both work with the latest versions!

So if you have this issue try downgrading to python-docker 2.3 first