Skip to content

Redis container port mapping

Redis container port mapping is the networking configuration that allows the Redis server running inside a Docker container to communicate with external services, typically by exposing the standard Redis port 6379.^[600-developer-docker-docker-compose-docker-redis.md, 600-developer__docker__docker-compose__docker-redis.md]

Configuration

When using Docker Compose, port mapping is defined in the docker-compose.yml file under the service definition.^[600-developer-docker-docker-compose-docker-redis.md, 600-developer__docker__docker-compose__docker-redis.md]

To map the port, the configuration utilizes the ports key with a host-to-container binding string.

redis:
 image: redis
 ports:
  - "6379:6379"

In the example configuration above, the string "6379:6379" maps port 6379 on the host machine to port 6379 within the container.^[600-developer-docker-docker-compose__docker-redis.md]

Accessing the Redis Client

Once the container is running with the correct port mapping, users can interact with the Redis instance. The standard method to enter the Redis command-line interface (CLI) from the host is via the Docker exec command:

docker exec -it 容器ID redis-cli^[600-developer-docker-docker-compose-docker-redis.md, 600-developer__docker__docker-compose__docker-redis.md]

Sources

^[600-developer-docker-docker-compose-docker-redis.md] ^[600-developer__docker__docker-compose__docker-redis.md]