1

I want to run network mode as host for Redis cluster in docker.

The command to execute in the redis image of docker hub, is written as follows.

docker run --name some-redis -d redis

After performing port mapping by giving the -p option as follows:

docker run -p 6379:6379 --name some-redis redis

If you connect to redis-cli, the connection is good.

> redis-cli -p 6379

127.0.0.1:6379>

If you look at the network with docker container inspect some-redis, the default network mode is bridge.

"Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,

I tried to proceed with the host.

docker run --net=host -p 6379:6379 --name some-redis redis
WARNING: Published ports are discarded when using host network mode

If a phrase such as, is displayed, the port is not disclosed.

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS          PORTS                                            NAMES
6f4edb2c4f8a   redis                        "docker-entrypoint.s…"   5 seconds ago    Up 4 seconds                                                     some-redis

Of course, you can't even connect to redis-cli.

> redis-cli -p 6379

Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>

Docker container doesn't expose ports when --net=host is mentioned in the docker run command

Looking at the above question, it seems that the port should be automatically public.

How can I expose ports in network mode host in docker redis?

battlecook
  • 471
  • 6
  • 17

1 Answers1

4

Check you machine, the --net=host only works in linux. https://docs.docker.com/network/host/

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Renshaw
  • 1,075
  • 6
  • 12
  • Oh my goodness.. I was running on wsl. I didn't know it
     is not supported on Docker Desktop for Mac, Docker Desktop for Windows,
    Thank you very much for the answer.
    – battlecook Mar 19 '21 at 08:33
  • 1
    Happy that helped you. You can accept my answer. – Renshaw Mar 19 '21 at 08:38