3👍
✅
The thing to understand here is that the container exposed ports != system exposed ports.
The Docker container for redis is exposing the port 6379 from the container — that is not the same port in the host system.
Assuming you’re running docker with:
docker run -ti redis bash
By default, Docker will choose a random port in the host to bind to the port the container is exposing. You can check the host ports with the command (will show nothing if no port is exposed):
docker port CONTAINER_ID
Instead, you’ll want to run it like this:
docker run -ti redis bash -p 6379:6379
This tells Docker to link the 6379 host port to the 6379 container port. Then docker port will show you something like this:
$ docker port CONTAINER_ID
6379/tcp -> 0.0.0.0:6379
You can also use a docker-compose.yml
file to configure this.
Read more:
Source:stackexchange.com