编写一个docker-compse.yml安装redis
时间: 2023-07-23 10:03:32 浏览: 115
Sure! Here is an example `docker-compose.yml` file for installing Redis using Docker Compose:
```yaml
version: '3'
services:
redis:
image: redis:latest
ports:
- 6379:6379
volumes:
- ./data:/data
```
In this configuration, we define a service named "redis" using the Redis image from Docker Hub. We map the container's port 6379 to the host's port 6379 to access Redis from outside the container. Additionally, we mount a local directory called "data" to the Redis container's "/data" directory to persist Redis data.
To use this `docker-compose.yml` file, save it to a directory and run the following command in that directory:
```
docker-compose up -d
```
This will start the Redis container in the background. You can then access Redis using the host's IP address and port 6379.
阅读全文