docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.92k stars 5.21k forks source link

Cannot start services when ports are mentioned #4729

Closed drgroot closed 7 years ago

drgroot commented 7 years ago

For some reason I cannot bind the port correctly. When I remove the port, it works. If i change the port to any other number, it still does not work

version: '3'
services:
  rtorrent:
    container_name: rtorrent
    image: yusufali/rtorrent
    privileged: true
  web_nginx:
    container_name: web_nginx
    image: marvambass/nginx-ssl-secure
    links:
      - rtorrent:rtorrent
    ports:
      - "8800:80"

However, run I run docker-com up -d, this does not work

Creating network "docker_default" with the default driver
Creating rtorrent
Creating web_nginx

ERROR: for web_nginx  Cannot create container for service web_nginx: invalid port specification: "None"
ERROR: Encountered errors while bringing up the project.

Useful info:

# docker-compose --version
docker-compose version 1.12.0, build b31ff33
# docker --version
Docker version 17.04.0-ce, build 4845c56
# uname -a
Linux gsad 4.4.30-mod-std-ipv6-64 #9 SMP Tue Nov 1 17:58:26 CET 2016 x86_64 GNU/Linux
shin- commented 7 years ago

That same setup works fine for me. Is that your entire docker-compose.yml file? Do you have a docker-compose.override.yml?

drgroot commented 7 years ago

No i do not.

shin- commented 7 years ago

Have you tried to isolate the issue into a smaller example? Do you still see the same bug with a simpler Compose file, e.g.

version: '3'
services:
  foo:
    image: alpine
    ports:
      - "8800:80"

Make sure it's in a separate, empty folder.

drgroot commented 7 years ago

same issue. done in a separate folder.

Its really weird cuz it works fine when I manually perform the operation using the 'docker create -p ...' command

shin- commented 7 years ago

Hmm, that's interesting. Did you install Compose using pip or did you download the binary? If you're using pip, what's your python --version? Also, could you run the following commands and share the output:

drgroot commented 7 years ago
pip3 install --upgrade docker-compose

$ python3 --version
  Python 3.4.2

For the docker-compose config:

Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.4/dist-packages/compose/cli/main.py", line 67, in main
    command()
  File "/usr/local/lib/python3.4/dist-packages/compose/cli/main.py", line 111, in perform_command
    handler(command, options, command_options)
  File "/usr/local/lib/python3.4/dist-packages/compose/cli/main.py", line 306, in config
    print(serialize_config(compose_config, image_digests))
  File "/usr/local/lib/python3.4/dist-packages/compose/config/serialize.py", line 62, in serialize_config
    width=80)
  File "/usr/local/lib/python3.4/dist-packages/yaml/__init__.py", line 216, in safe_dump
    return dump_all([data], stream, Dumper=SafeDumper, **kwds)
  File "/usr/local/lib/python3.4/dist-packages/yaml/__init__.py", line 188, in dump_all
    dumper.represent(data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 26, in represent
    node = self.represent_data(data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[None](self, data)
  File "/usr/local/lib/python3.4/dist-packages/yaml/representer.py", line 229, in represent_undefined
    raise RepresenterError("cannot represent an object: %s" % data)
yaml.representer.RepresenterError: cannot represent an object: <map object at 0x77fd26e406a0>

Docker compose verbose,


root@bilbo:/home/media# docker-compose --verbose up -d
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.find_config_file: Trying paths: ['/root/.docker/config.json', '/root/.dockercfg']
docker.auth.find_config_file: No config file found
compose.cli.command.get_client: docker-compose version 1.12.0, build b31ff33
docker-py version: 2.2.1
CPython version: 3.4.2
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: GitCommit=4845c56, MinAPIVersion=1.12, Arch=amd64, BuildTime=2017-04-03T17:45:49.040323876+00:00, KernelVersion=3.14.32-xxxx-grs-ipv6-64, Version=17.04.0-ce, ApiVersion=1.28, GoVersion=go1.7.5, Os=linux
compose.cli.verbose_proxy.proxy_callable: docker info <- ()
compose.cli.verbose_proxy.proxy_callable: docker info -> {'Architecture': 'x86_64',
 'BridgeNfIp6tables': True,
 'BridgeNfIptables': True,
 'CPUSet': True,
 'CPUShares': True,
 'CgroupDriver': 'cgroupfs',
 'ClusterAdvertise': '',
 'ClusterStore': '',
 'ContainerdCommit': {'Expected': '422e31ce907fd9c3833a38d7b8fdd023e5a76e73',
                      'ID': '422e31ce907fd9c3833a38d7b8fdd023e5a76e73'},
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('media_default')
compose.network.ensure: Creating network "media_default" with the default driver
compose.cli.verbose_proxy.proxy_callable: docker create_network <- (driver=None, attachable=True, options=None, ipam=None, enable_ipv6=False, name='media_default', labels={'com.docker.compose.project': 'media', 'com.docker.compose.network': 'default'}, internal=False)
compose.cli.verbose_proxy.proxy_callable: docker create_network -> {'Id': '6a361460c517da0f8c8742f77ce9e76a474d8e5dbf24404b47cbea02ab138a99',
 'Warning': ''}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={'label': ['com.docker.compose.project=media', 'com.docker.compose.oneoff=False']}, all=False)
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={'label': ['com.docker.compose.project=media', 'com.docker.compose.service=foo', 'com.docker.compose.oneoff=False']}, all=True)
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('alpine')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': None,
            'Domainname': '',
            'Entrypoint': None,
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={'label': ['com.docker.compose.project=media', 'com.docker.compose.service=foo', 'com.docker.compose.oneoff=False']}, all=True)
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.parallel.feed_queue: Pending: {<Service: foo>}
compose.parallel.feed_queue: Starting producer thread for <Service: foo>
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('alpine')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': None,
            'Domainname': '',
            'Entrypoint': None,
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={'label': ['com.docker.compose.project=media', 'com.docker.compose.service=foo', 'com.docker.compose.oneoff=False']}, all=True)
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('alpine')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': None,
            'Domainname': '',
            'Entrypoint': None,
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.service.build_container_labels: Added config hash: df12277d2b94980b1245953ec768c3916e94b9228becf2a5615e95a786b82771
compose.cli.verbose_proxy.proxy_callable: docker create_host_config <- (cpu_quota=None, cap_add=None, port_bindings={'None/tcp': [None]}, cap_drop=None, devices=None, cgroup_parent=None, dns_search=None, dns=None, userns_mode=None, extra_hosts=None, oom_score_adj=None, dns_opt=None, shm_size=None, log_config={'Type': '', 'Config': {}}, group_add=None, pids_limit=None, pid_mode=None, ipc_mode=None, binds=[], memswap_limit=None, ulimits=None, security_opt=None, read_only=None, tmpfs=None, sysctls=None, mem_swappiness=None, mem_reservation=None, privileged=False, mem_limit=None, restart_policy=None, links=[], volumes_from=[], network_mode='media_default')
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': [],
 'Links': [],
 'LogConfig': {'Config': {}, 'Type': ''},
 'NetworkMode': 'media_default',
 'PortBindings': {'None/tcp': [{'HostIp': '', 'HostPort': ''}]},
 'VolumesFrom': []}
compose.service.create_container: Creating media_foo_1
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (detach=True, volumes={}, name='media_foo_1', host_config={'VolumesFrom': [], 'NetworkMode': 'media_default', 'Links': [], 'Binds': [], 'Isolation': None, 'PortBindings': {'None/tcp': [{'HostIp': '', 'HostPort': ''}]}, 'LogConfig': {'Type': '', 'Config': {}}}, ports=[('None', 'tcp')], image='alpine', networking_config={'EndpointsConfig': {'media_default': {'IPAMConfig': {}, 'Aliases': ['foo']}}}, labels={'com.docker.compose.service': 'foo', 'com.docker.compose.oneoff': 'False', 'com.docker.compose.container-number': '1', 'com.docker.compose.config-hash': 'df12277d2b94980b1245953ec768c3916e94b9228becf2a5615e95a786b82771', 'com.docker.compose.version': '1.12.0', 'com.docker.compose.project': 'media'}, environment=[])
compose.parallel.parallel_execute_iter: Failed: <Service: foo>
compose.parallel.feed_queue: Pending: set()

ERROR: for foo  Cannot create container for service foo: invalid port specification: "None"
ERROR: compose.cli.main.main: Encountered errors while bringing up the project.
shin- commented 7 years ago

It might be an issue with Python 3 - I'll take another look. In the meantime, you might want to try using Python 2.7 instead and see if the issue still occurs.

drgroot commented 7 years ago

okay, switching to python 2 works.

dalberto commented 7 years ago

I've experienced the same issue on Python 3.5, installed via pip. Similarly, using python 2 fixes the issue. I experienced the issue with file versions 2.1 and 3.0, 3.2 but not 3.1.

dpdornseifer commented 7 years ago

Hi experiencing the same problem just with Python3.5.0. 2.7 and 3.5.1 / 3.5.2 / 3.5.3 are working fine. A quickfix for me right now is to to use docker-compose < 1.12.0

shin- commented 7 years ago

I believe this Python bug is the cause of the issue: https://bugs.python.org/issue24931 Upgrading to Python 3.4.4+ or 3.5.1+ should fix it.

svitlanacs commented 7 years ago

@dpdornseifer could you, please, share the command you used to downgrade the docker-compose?

Found it! For anybody interested in how to downgrade docker-compose, this link was useful for me: https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-ubuntu-16-04

shin- commented 7 years ago

@svitlanacs Please note that a much better solution would be to upgrade your Python installation.

svitlanacs commented 7 years ago

@shin- absolutely. But I'm running Ubuntu 14.04, so downgrading docker-compose was a simpler solution.

z3ntu commented 7 years ago

I also downgraded to 1.11.2 as the Python version on Ubuntu 14.04 is 3.4.3.

harpcio commented 6 years ago

I have the same issue on python 2.7.6 / ubuntu 14.04.05 LTS with docker-compose version: "2.1". Switching to version: '2' have fixed the problem.

OleksiiStepanov commented 5 years ago

I had same error with my port map and i solved that. Just wrote a map as string

ports:
    - 8080:80
... 

replace with:

ports:
    - "8080:80"
...

i am using docker-compose version 1.21.2, build a133471