docker-library / docker-library/mongo

mongo in the container does not properly listen on IPv6

Open
#691 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
1.1k
Forks
658
Avg merge
4h 40m
Merged PRs (30d)
1

Description

Hi everyone,

I have encountered a bug where the official Mongo image does not properly enable MongoDB to listen on IPv6 address(es).

I have tried two cases:

  • default setting (docker-entrypoint.sh sets "--bind-all")
  • manual override of the start-up arguments to use --bind_ip::,0.0.0.0

In both cases Mongo listens on just 0.0.0.0:27017. Connections from other containers in a docker-compose built environment may result in connection issues (if the app only tries IPv6 and does not fall back to IPv4).

I had to add the command: mongod --auth --ipv6 --bind_ip ::,0.0.0.0 line to my docker-compose.yaml to get this working.

Proposal:

  • the --ipv6 argument should be always added as part of the docker-entrypoint.sh when the bind-all argument is added by the docker-entrypoint.sh and the container is IPv6-enabled
  • the --ipv6 argument should be always added as part of the docker-entrypoint.sh when the bind_ip argument contains an IPv6 address.

Thank you for looking into this issue.

Environment:

  1. Dual-stacked (IPv4+IPv6) Docker network
  2. Default latest mongo image
# docker image inspect mongo
[
    {
        "Id": "sha256:6cce01a3be94671985ff01c97275ad73fcf6968736e662951cf7cc7045589ceb",
        "RepoTags": [
            "mongo:latest"
        ],
        "RepoDigests": [
            "mongo@sha256:0907ce5de8b9aee1935e43fb6e20f80297a08c90de71c0c2b44f9b3ecc9d4906"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2024-04-03T16:02:10Z",
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "27017/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.17",
                "JSYAML_VERSION=3.13.1",
                "MONGO_PACKAGE=mongodb-org",
                "MONGO_REPO=repo.mongodb.org",
                "MONGO_MAJOR=7.0",
                "MONGO_VERSION=7.0.8",
                "HOME=/data/db"
            ],
            "Cmd": [
                "mongod"
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": {
                "/data/configdb": {},
                "/data/db": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "org.opencontainers.image.ref.name": "ubuntu",
                "org.opencontainers.image.version": "22.04"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 794785163,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/587aab40c47b7be6ed1c8138ca70deae5619efab3010fefbfb8dcea45aefa05f/diff:/var/lib/docker/overlay2/1e55ae391eadf8c5e24ecb5dfc6026d763479493e07ea2ce29a9e7a3d329d94a/diff:/var/lib/docker/overlay2/fe5d0b62ebc7a4f896998a6a23138ff4d22bda65a2c8b33b7254e5b879820556/diff:/var/lib/docker/overlay2/9c433ec3a3898756e33220498e8249f4bedbdcd2391bd1f41c2c949267807e3a/diff:/var/lib/docker/overlay2/47cf7e16c58d8e9bda9bbedef09f2b17b3be41c36b7373fac98ca12321f9b507/diff:/var/lib/docker/overlay2/195b8e05cbbd66f23fface9c84d0a62c10f3a84f6f7b73b5d16ae76b5d430644/diff:/var/lib/docker/overlay2/a57a811ae6669f5c774715bdc32cdcee51af51bc88e423746b6cf60e00e51fa9/diff",
                "MergedDir": "/var/lib/docker/overlay2/c92d8dc73e1f5be737f9769c4012925b38e908806bec875918d15da20ad770d6/merged",
                "UpperDir": "/var/lib/docker/overlay2/c92d8dc73e1f5be737f9769c4012925b38e908806bec875918d15da20ad770d6/diff",
                "WorkDir": "/var/lib/docker/overlay2/c92d8dc73e1f5be737f9769c4012925b38e908806bec875918d15da20ad770d6/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:b706c187b212a5c2242e664f21d3eb12fee4c1e150b300d12035284d53c56b7a",
                "sha256:2bda7597f9322f01c94509c4e81d6a7a1809f2022f9bc443397249851b9654ca",
                "sha256:1b3d7e280970c1e34ae77e6bad2887f80bbbe80e5b848e99f637fda900eef2b1",
                "sha256:9d0d44963fda36c34da91c736dd59d84e0e17b4da43fcee0fc04c5e5d3697015",
                "sha256:daac870a250b21439f2b9f739f2b64f4fe7c40c699d2305ab3704cbd9bb5b128",
                "sha256:1a10a0799170e7c12b45ae2637a889d01a819e88ad4c922fa41929416504e6c7",
                "sha256:fcb1ba1bd1076dc455da7f10172e2e8196252fcd89d4f71181bbbb23ed394cfa",
                "sha256:6e81c9c7f811ebd0a5610932feacf4b0b2903ba3187e1eb74f54211df969ccb2"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in docker-entrypoint.sh, especially the handling of --bind-all and --bind_ip, and reproduce the report on a dual-stacked Docker network. Verify that the resulting mongod process listens on IPv6 for the proposed argument cases while preserving IPv4 listening; done means connections from other containers can use IPv6 without a manual docker-compose command override.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, mongodb, shell
Domain
devops, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.