-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Direct redis access, redis-cli and pub/sub build #229
Comments
Hello @cevanno, You can't access the port because Redis is listening only on You can instruct Redis to listen on all interfaces within the container, just like Webdis has to do with As documented in With the diff --git Dockerfile Dockerfile
index d77b5ee..8cec061 100644
--- Dockerfile
+++ Dockerfile
@@ -14,7 +14,7 @@ FROM alpine:3.14.3
RUN apk update && apk add libevent msgpack-c 'redis>6.2.6' openssl libssl1.1 libcrypto1.1 && rm -f /var/cache/apk/* /usr/bin/redis-benchmark /usr/bin/redis-cli
COPY --from=stage /usr/local/bin/webdis /usr/local/bin/webdis-ssl /usr/local/bin/
COPY --from=stage /etc/webdis.prod.json /etc/webdis.prod.json
-RUN echo "daemonize yes" >> /etc/redis.conf
+RUN echo "daemonize yes" >> /etc/redis.conf && echo 'bind * -::*' >> /etc/redis.conf
CMD /usr/bin/redis-server /etc/redis.conf && /usr/local/bin/webdis /etc/webdis.prod.json
-EXPOSE 7379
+EXPOSE 7379 6379 I built it as docker build -t webdis:issue229 . and then ran it as a foreground container in the same terminal: docker run --rm -p 127.0.0.1:7379:7379 -p 127.0.0.1:6379:6379 webdis:issue229 In a separate terminal, I was able to verify that both HTTP requests and $ curl -s http://127.0.0.1:7379/PING
{"PING":[true,"PONG"]}
$ redis-cli ping
PONG As for the two config files, the idea is to have two different files for two use cases:
From what I understand it sounds like you're planning to run a custom image with these minor port changes, so if you want to also enable websockets you'd need to either make the change in -RUN sed -i -e 's/"daemonize":.*true,/"daemonize": false,/g' /etc/webdis.prod.json
+RUN sed -i -e 's/"daemonize":.*true,/"daemonize": false, "websockets": true,/g' /etc/webdis.prod.json Make sure not to miss the trailing comma after With all of these changes, the full Dockerfile could look like this: FROM alpine:3.14.3 AS stage
LABEL maintainer="Nicolas Favre-Felix <n.favrefelix@gmail.com>"
RUN apk update && apk add wget make gcc libevent-dev msgpack-c-dev musl-dev openssl-dev bsd-compat-headers jq
RUN wget -q https://api.github.com/repos/nicolasff/webdis/tags -O /dev/stdout | jq '.[] | .name' | head -1 | sed 's/"//g' > latest
RUN wget https://github.com/nicolasff/webdis/archive/$(cat latest).tar.gz -O webdis-latest.tar.gz
RUN tar -xvzf webdis-latest.tar.gz
RUN cd webdis-$(cat latest) && make && make install && make clean && make SSL=1 && cp webdis /usr/local/bin/webdis-ssl && cd ..
RUN sed -i -e 's/"daemonize":.*true,/"daemonize": false, "websockets": true,/g' /etc/webdis.prod.json
# main image
FROM alpine:3.14.3
# Required dependencies, with versions fixing known security vulnerabilities
RUN apk update && apk add libevent msgpack-c 'redis>6.2.6' openssl libssl1.1 libcrypto1.1 && rm -f /var/cache/apk/* /usr/bin/redis-benchmark /usr/bin/redis-cli
COPY --from=stage /usr/local/bin/webdis /usr/local/bin/webdis-ssl /usr/local/bin/
COPY --from=stage /etc/webdis.prod.json /etc/webdis.prod.json
RUN echo "daemonize yes" >> /etc/redis.conf && echo 'bind * -::*' >> /etc/redis.conf
CMD /usr/bin/redis-server /etc/redis.conf && /usr/local/bin/webdis /etc/webdis.prod.json
EXPOSE 7379 6379 I hope this helps! Let me know if you're still blocked after this. |
Thanks! I had found the same kinds of solutions. Your solutions for the redis.conf file did not work without a little tweak and gives this error: Removing the 127.0.0.1's let it start but all pubsub SUBSCRIBE messages get the "Error: Server closed the connection" And this works in my environment. Since your test passed there is some difference in our environments that might be a problem? A problem I see with your fix to
Do you agree this is better? |
Glad you managed to make progress! I'm surprised you got an error with the
The error message you pasted is saying that you already have a process listening on port 6379, likely either from a previous Webdis+Redis container that was still running or from a local Redis service. You can find this mystery process with the following command on macOS: sudo lsof -i -P -n | grep LISTEN | grep :6379 or this way on most Linux distros: sudo netstat -nlp | grep :6379 Reading the documentation for So I'm not sure why we're observing some differences in behavior, it's certainly unexpected given that Docker is supposed to be a way to neatly package and run software the same way regardless of the host OS. For what it's worth I ran the commands above with Docker Desktop 4.15.0 (93002) on macOS 12.6. It's possible that the way Redis sees the incoming connection as being made on loopback or not depends on the version of Docker and the host it runs on, hence the difference in whether
This is really up to you, and how you want to manage this file. I don't think there's a fundamental difference, you can achieve the same results either way. I'd say the main difference is this: the advantage of pulling the file from the downloaded archive is that you only need to maintain the |
OK, all good. Yes I had a zombie process as you suspected and after removing it the -p 127.0.0.1:6379:6379 form ran with 'docker run' |
I'd like to use your app as a docker image for pub/sub and database services, and keep redis in the same image. For testing and maintenance I want to still have access to redis directly (to use redis-cli and redis-desktop) while also using the webdis frontend for production network apps. But even though I EXPOSE ports 7379 6379 in the Dockerfile and then do 'docker run -p 7379:7379 -p 6379:6379' the container does not respond to redis commands or the redis-cli. The terminal says "Error: Server closed the connection" and the webdis.log doesn't even have an entry that the command was attempted. Is external redis access blocked? Can it be unblocked?
Just as a test I ran a generic Redis image in docker and exposed port 6379 in the launch and I can communicate with it with redis-cli from another location (WSL Ubuntu in my case), so this is why I think something in this code or config is blocking redis from external access.
For pub/sub I set "websockets"=true in webdis.json as the readme instructs, but there is also a webdis.prod.json that appears to be used in the Dockerfile as the "authoritive" config file so NOT modifying that one seems 'wrong'? Can you confirm that this file is ignored from my perspective?
The text was updated successfully, but these errors were encountered: