zkteco-home / redis-windows

Native port of Redis for Windows,it can be installed as service.
MIT License
1.91k stars 173 forks source link

Docker: Working Example? #12

Closed nfMalde closed 2 years ago

nfMalde commented 2 years ago

Thanks for porting Redis 7 to Windows. I was trying to make it runnable in the docker env by reproducing the steps of the 3.x redis version for windows containers: https://hub.docker.com/layers/redis/library/redis/windowsservercore/images/sha256-0a2ce94c3cdb33b022c12c24fb256cd3059585ef4e914e82000fd05850eec176?context=explore

Redis 3.x is not longer working with up2date StackExchange Extension for .net 6. However after reproducing the above config I recieve from redis: "no active connection available".

Docker file I made below:

# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as base
ENV REDIS_DOWNLOAD_URL=https://github.com/zkteco-home/redis-windows/archive/refs/tags/redis7.0.zip
ENV REDIS_NAME="redis-windows-redis7.0"

FROM base as download
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /
# Setup Environment
RUN `
$newPath = ('C:\Redis;{0}' -f $env:PATH);`
Write-Host ('Updating PATH: {0}' -f $newPath);`
setx /M PATH $newPath;
# Install
RUN `
Write-Host ('Downloading {0} ...' -f $env:REDIS_DOWNLOAD_URL);`
Invoke-WebRequest -Uri $env:REDIS_DOWNLOAD_URL -OutFile 'redis.zip';`
Write-Host 'Expanding ...';`    
Expand-Archive redis.zip -DestinationPath C:\redis-download; `
mkdir "Redis";`
Get-ChildItem -Path "C:\\redis-download\\$($env:REDIS_NAME)" -Recurse -File | Move-Item -Verbose -Force -Destination "Redis";`

Write-Host 'Verifying install ("redis-server --version") ...';`
redis-server --version;`
Write-Host 'Removing ...';`
Remove-Item redis.zip -Force
RUN dir

WORKDIR /   
RUN mkdir C:\data
VOLUME C:\data

WORKDIR /data

ADD ["redis.docker.conf", "/Redis"]
ADD ["redis.windows.conf", "/Redis"]
RUN (Get-Content C:\Redis\redis.windows.conf)   -Replace '^(bind)\s+.*$', '$1 0.0.0.0'  -Replace '^(protected-mode)\s+.*$', '$1 no'     | Set-Content C:\Redis\redis.docker.conf

EXPOSE 6379/tcp
ENTRYPOINT [ "redis-server.exe", "redis.docker.conf" ]
zkteco-home commented 2 years ago

"no active connection available" means connect failed,it does not respond by redis.you can use redis-cli.exe to test it