资源
docker redis 镜像官网 1. 获取redis的配置文件2. 添加 `Dockerfile` 文件3. 添加运行脚本
问: 如何解决报错: unable to prepare context ? 4. build 成功5. 运行容器
问: docker -v 选项能使用 相对路径吗?问: 为什么无法连接docker 中的redis ? 需要配置 redis.conf ? 6. 使用 docker 客户端连接
资源 docker redis 镜像官网Redis - Official Image | Docker Hub
1. 获取redis的配置文件wget https://download.redis.io/redis-stable/redis.conf2. 添加 Dockerfile 文件
# Dockerfile 文件, 名字不能变, 否则需要手动指定dockerfile的文件名 FROM redis:6.2.6 COPY redis.conf /usr/local/etc/redis/redis.conf CMD ["redis-server","/usr/local/etc/redis/redis.conf"]3. 添加运行脚本
# build-docker.sh docker build -t myredis:v1 .问: 如何解决报错: unable to prepare context ?
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:UsersAdministratorDesktoptestdockerDockerfile: The system cannot find the file specified. Dockerfile 文件, 名字不能变, 否则需要手动指定dockerfile的文件名 ```bash docker build -t4. build 成功 5. 运行容器:[tag] -f ```
docker run -it -p 6379:6379 myredis:v1
有问题, 这样运行之后无法连上redis, 而直接运行的docker是可以连上的, 但是却无法指定配置文件的路径…
附: 单独运行 docker 的脚本
mkdir conf
if ! [[ -f "./conf/redis.conf" ]] then
wget https://download.redis.io/redis-stable/redis.conf -o conf/redis.conf
fi
docker run --rm -it --network bridge
-p 6379:6379 -v /usr/etc/redis/conf:/data/conf
redis:6.2.6 redis-server /data/conf/redis.conf
问: docker -v 选项能使用 相对路径吗?
-v 映射的路径没有使用绝对路径导致的, 他的路径可能不是相对当前目录的, 不允许 ./ 开头的,会有下面这个错
docker: Error response from daemon: create ./conf: "./conf" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path. See 'docker run --help'.问: 为什么无法连接docker 中的redis ? 需要配置 redis.conf ?
我发现只要指定了配置文件, 就没有办法运行, 说明是配置文件的问题, 需要把 bind 配置为
bind * -::*
https://stackoverflow.com/questions/41371402/connecting-to-redis-running-in-docker-container-from-host-machine
6. 使用 docker 客户端连接# 需要用虚拟机的ip 而不是 127.0.0.1, 用 127.0.0.1 是连不上的 docker run --rm -it --network bridge redis:6.2.6 redis-cli -h 192.168.168.20 -p 6379



