Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose fails to parse ports from the compose file #4967

Closed
omerh opened this issue Jun 28, 2017 · 9 comments
Closed

docker-compose fails to parse ports from the compose file #4967

omerh opened this issue Jun 28, 2017 · 9 comments

Comments

@omerh
Copy link

omerh commented Jun 28, 2017

I hame having some weird issue now.
I have a fresh install docker with docker compose
docker version: 17.03.2-ce
docker-compose: 1.14.0, build c7bdf9e
running on ubuntu 16.04

I am trying to run the following compose file:

version: "3"
services:
  web:
    image: tutum/hello-world
    ports:
     - "86:80"

And I am getting port parse exception when running the command:

docker-compose -f test.yml up -d

The exception is:

ERROR: for web  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

I have tried downgrading to 1.13.0 and issue still persists.
after downgrading to 1.7.0 it works as expected

@tobiashuste
Copy link

For me it seems to be due to a version update of one of the dependencies.
I installed the dependencies as given in requirements.txt with:

pip install -r requirements.txt

After that, the error was gone.

@skinofstars
Copy link

skinofstars commented Jun 28, 2017

The problem was the docker-py version. You can have just docker==2.3.0 in your requirements.txt for now.

docker/docker-py#1668

@Ingramz
Copy link

Ingramz commented Jun 28, 2017

I inspected the issue and it seems like compose is passing at some point strings like this to be parsed as ports: ServicePort(target=5000, published=5000, protocol=None, mode=None, external_ip=None), however it also passes the same thing earlier correctly 5000:5000

2.3.0 simply didn't raise an error and the incorrectly parsed string probably gets ignored eventually. I'm still looking where compose is passing ServicePort, that should be fixed.

@Ingramz
Copy link

Ingramz commented Jun 28, 2017

Problem is definitely here:

compose/compose/service.py

Lines 966 to 991 in 4dd54b8

def specifies_host_port(self):
def has_host_port(binding):
if isinstance(binding, dict):
external_bindings = binding.get('published')
else:
_, external_bindings = split_port(binding)
# there are no external bindings
if external_bindings is None:
return False
# we only need to check the first binding from the range
external_binding = external_bindings[0]
# non-tuple binding means there is a host port specified
if not isinstance(external_binding, tuple):
return True
# extract actual host port from tuple of (host_ip, host_port)
_, host_port = external_binding
if host_port is not None:
return True
return False
return any(has_host_port(binding) for binding in self.options.get('ports', []))

More specifically on line:
_, external_bindings = split_port(binding)

where an instance of ServicePort is being passed. To get rid of the error, it should be sufficient to pass legacy representation instead:
_, external_bindings = split_port(binding.legacy_repr())

I will leave this to someone who actually knows what specifies_host_port is supposed to do and knows how to verify all possible code paths through this method.

@andreabenfatto
Copy link

andreabenfatto commented Jun 28, 2017

same error here :(
@Ingramz solution works for me.

@omerh
Copy link
Author

omerh commented Jun 28, 2017

I have tried installing the requirements.txt and it didnt worked.
I have also tried to modify the compose to the full syntax of ports declaration in YML
issue still pressists

@leandro-lugaresi
Copy link

Problem solved with a downgrade of python-docker from 2.4.0 to 2.3.0
sudo pacman -U /var/cache/pacman/pkg/python-docker-2.3.0-1-any.pkg.tar.xz

@camilo0365
Copy link

camilo0365 commented Jun 28, 2017

$ pip uninstall docker
$ pip install docker==2.3.0

This did the trick for me. Prefix it with sudo if you want to overwrite the system library :)

@shin-
Copy link

shin- commented Jul 12, 2017

Somehow I missed this issue - sorry!
You should be able to upgrade docker to 2.4.2 now. See #4972

@shin- shin- closed this as completed Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants