moby / swarmkit

A toolkit for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and more.
Apache License 2.0
3.34k stars 611 forks source link

if the image does not EXPOSE a port I can not bind it during docker service create #1717

Closed rolele closed 7 years ago

rolele commented 7 years ago

I am using this docker image: https://github.com/wurstmeister/kafka-docker

I noticed that there is no EXPOSE command in the Dockerfile

creating the service using docker service

docker service create
  --name kafka_name
  --label name=kafka_name
  --constraint 'node.labels.managers == true'
  -e KAFKA_ADVERTISED_HOST_NAME=kafka_name
  -e KAFKA_ADVERTISED_PORT=9092
  -e KAFKA_ZOOKEEPER_CONNECT=zookeeper_name:2181
  -e KAFKA_CREATE_TOPICS="kafkapipeline:1:1"
  -p 9092:9092/tcp
  --network appnet
  {wurstmeister/kafka-docker

will result in the service without binding on port 9092

[root@worker0 vagrant]# docker ps
CONTAINER ID        IMAGE                       COMMAND             CREATED             STATUS              PORTS               NAMES
c37ce90315cf        wurstmeister/kafka:latest   "start-kafka.sh"    23 seconds ago      Up 21 seconds                           kafka.1.5wcrr2gbvq01qd0bci35xl52m
[root@worker0 vagrant]# docker inspect c37ce90315cf
[
    {
        "Id": "c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07",
        "Created": "2016-10-30T05:09:19.350139312Z",
        "Path": "start-kafka.sh",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 28450,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-10-30T05:09:21.951872161Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:d113cf30cc69c216e9b93d21704e5f896210feab383e51cf9f7f07b1b5e96b2f",
        "ResolvConfPath": "/var/lib/docker/containers/c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07/hostname",
        "HostsPath": "/var/lib/docker/containers/c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07/hosts",
        "LogPath": "/var/lib/docker/containers/c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07/c37ce90315cfb230a39d0ece7ec94118f9dce8d62f13856158f2b9ed74288f07-json.log",
        "Name": "/kafka.1.5wcrr2gbvq01qd0bci35xl52m",
        "RestartCount": 0,
        "Driver": "devicemapper",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],"Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "devicemapper",
            "Data": {
                "DeviceId": "166",
                "DeviceName": "docker-253:0-202781583-4aae7ae7b173bbdb8069f893b92ac09c9640f72c2798e65b61829c8dd33b0f53",
                "DeviceSize": "10737418240"
            }
        },
        "Mounts": [
            {
                "Name": "25615fd0f7005251f6ed466f4cb9c977da18ff9da0f8791e9a08153340b6f96a",
                "Source": "/var/lib/docker/volumes/25615fd0f7005251f6ed466f4cb9c977da18ff9da0f8791e9a08153340b6f96a/_data",
                "Destination": "/kafka",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "c37ce90315cf",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "KAFKA_ADVERTISED_HOST_NAME=kafka",
                "KAFKA_ADVERTISED_PORT=9092",
                "KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181",
                "KAFKA_CREATE_TOPICS=kafkapipeline:1:1",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/jdk/bin",
                "JAVA_VERSION_MAJOR=8",
                "JAVA_VERSION_MINOR=102",
                "JAVA_VERSION_BUILD=14",
                "JAVA_PACKAGE=server-jre",
                "JAVA_JCE=standard",
                "JAVA_HOME=/opt/jdk",
                "GLIBC_VERSION=2.23-r3",
                "LANG=C.UTF-8",
                "KAFKA_VERSION=0.10.1.0",
                "SCALA_VERSION=2.11",
                "KAFKA_HOME=/opt/kafka_2.11-0.10.1.0"
            ],
"Cmd": [
                "start-kafka.sh"
            ],
            "Image": "wurstmeister/kafka:latest",
            "Volumes": {
                "/kafka": {}
            },
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "com.docker.swarm.node.id": "3htayovwreiwndurqmodap063",
                "com.docker.swarm.service.id": "an7lb6whbqszbcpmpz9cwnzs8",
                "com.docker.swarm.service.name": "kafka",
                "com.docker.swarm.task": "",
                "com.docker.swarm.task.id": "5wcrr2gbvq01qd0bci35xl52m",
                "com.docker.swarm.task.name": "kafka.1"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "d561843ef9695bbffbff4eecedf8bf4e01269905943c4254ad14f5407de09994",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/d561843ef969",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "appnet": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.0.95"
                    },
                    "Links": null,
                    "Aliases": [
                        "c37ce90315cf"
                    ],
                    "NetworkID": "2rdpiicln2ve6s3habtm7pvcd",
                    "EndpointID": "d21353621c9bd8bac09d290a25da94452b6f913d4265d2538a3c47476fe6d4cb",
                    "Gateway": "",
                    "IPAddress": "10.0.0.95",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:00:00:5f"
                },
                "ingress": {
                    "IPAMConfig": {
                        "IPv4Address": "10.255.0.99"
                    },
                    "Links": null,
                    "Aliases": [
                        "c37ce90315cf"
                    ],
                    "NetworkID": "f1d32ji17ohqt5g7vdlflspaa",
                    "EndpointID": "6e864a5976fc9d1352c48a7523f37332ae0870d5c2d79380ddd2d3aaf504f543",
                    "Gateway": "",
                    "IPAddress": "10.255.0.99",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:ff:00:63
}
            }
        }
    }
]

I have never experienced this with standalone docker. Am I missing something?

thaJeztah commented 7 years ago

Ports that are published for services don't show up in docker ps, or docker inspect for individual containers, because the individual container's ports are not published directly, but published through the built in load balancer.

You can see that the port is published for the service if you docker service inspect <service name>

thaJeztah commented 7 years ago

Note that EXPOSE is only used if you -P (capital "p"), to automatically publish all exposed ports, but not required if you explicitly publish a specific port (-p <port>:<port>)

rolele commented 7 years ago

thanks @thaJeztah I tried docker service inspect <service name> and I could see that 9092 is exposed by the service.

Can you tell me why all my other services have a PORTS display during docker ps but not the kafka service ( I am talking about the PORTS column of docker ps)

root@manager0 vagrant]# docker ps
CONTAINER ID        IMAGE                           COMMAND             CREATED             STATUS              PORTS               NAMES
bcdd4c7b3a7c        wurstmeister/kafka:latest       "start-kafka.sh"    2 minutes ago       Up 2 minutes                            kafka.1.6d3hpnvywytaidsfveuduu4n1
6c872105a1da        aaaaaaaa/scrapy-alpine:latest   "scrapyd"           About an hour ago   Up About an hour    6800/tcp            scrapy_container.0.6vejpjs9z8nbwt8woxv4nhct7
8aede78ca618        uifd/ui-for-docker:latest       "/ui-for-docker"    5 hours ago         Up 5 hours          9000/tcp            docker-ui.0.cwtszj4g5fvmln5lwm76ocxpk

I am using the exact same principale to start my other services.

thaJeztah commented 7 years ago

that's the way docker ps shows containers that have an EXPOSE, so only "informational", but there's no functional difference

rolele commented 7 years ago

I understand. thanks

thaJeztah commented 7 years ago

FWIW, this is on our radar; we do want to improve this as we understand it's a bit confusing