Redis server on diffrent node using docker on ubuntu 20 - redis

i want to setup redis cluster on 3 diffrent nodes using docker..can any one suggest the commands or some documents for setup?
i am finding the documents for single node but i want it for multiple nodes
any help would be appriciated
Thank you!

so i followed these steps to setup redis cluster on 3 diffrent servers.
add entries in nano /etc/hosts file on all the nodes 3 nodes
ip1 hostname1
ip2 hostname2
ip3 hostname3
then save and exit
on node1
docker run --name redis-node-1 --hostname hostname1 --net test -p 6379:6379 -p 16379:16379 -d redis redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000
on node2
docker run --name redis-node-2 --hostname hostname2 --net test -p 6379:6379 -p 16379:16379 -d redis redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000
on node3
docker run --name redis-node-3 --hostname hostname3 --net test -p 6379:6379 -p 16379:16379 -d redis redis-server --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000
now once all 3 containers are up run the below command on any node.i am running it on 1st node.
docker exec -it redis-node-1 redis-cli --cluster create ip1:6379 ip2:6379 ip3:6379 --cluster-replicas 0
after the setup is complete verify it with below command
docker exec -it redis-node-1 redis-cli cluster info
This worked for me ..Thank you!

Related

redis container how to load lua script from host

I am trying to execute a lua script against a redis instance running in a container. The code is very simple 2 liner example.
local foo = redis.call("ping")
return foo
As this file is on the host machine, how do i get it to execute inside docker exec ? Or should I install redis-cli locally to test it?
I think I understood what you want. You have a Lua script on your docker host that you want to load into Redis running inside a docker container without needing redis-cli on the host.
So, start the official Redis in a container as a daemon:
docker run --name some-redis -d redis
Now, assuming your script is on the host in a file called script.lua, you want to load that into dockerised Redis:
docker exec -i some-redis redis-cli -x script load < script.lua
That will return a SHA sum - I got 93126620988a563ac9dd347d02a9cdbbbeaee3c1 - and you can then run the script with:
docker exec -i some-redis redis-cli EVALSHA 93126620988a563ac9dd347d02a9cdbbbeaee3c1 0
PONG
If you want to automate the capture of the SHA sum and its subsequent use:
sha=$(docker exec -i some-redis redis-cli -x script load < script.lua)
Then:
docker exec -i some-redis redis-cli EVALSHA $sha 0
PONG

Localstack Service "s3" not yet available, retrying

Service "S3" not yet available, retrying.
I am using localstack docker image.
When I am hitting the command:
docker run -it -p 4567-4578:4567-4578 -p 8080:8080 localstack/localstack
I am getting errors: S3 is not yet available
I am using MacOS.
I got the solution.
Try to run the services that you need.
docker run -p 4569:4569 -p 4572:4572 -p 4575:4575 -p 4576:4576 -e SERVICES=dynamodb,s3,sns,sqs -p 8080:8080 localstack/localstack

Loading initial data into a Redis Docker container

I'm trying to create a Redis Docker image, based on the redis:3. However, I need to load a small amount of test data into the image (it is used for testing, both on developer machines and on the CI server).
My initial attempt looks like:
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN redis-cli sadd production-stores 5555
But this fails with the error:
Step 2 : RUN redis-cli sadd production-stores 5555
---> Running in 60fb98c133c0
Could not connect to Redis at 127.0.0.1:6379: Connection refused
The command '/bin/sh -c redis-cli sadd production-stores 5555' returned a non-zero code: 1
I'm wondering if there's a trick that allows me, in a Docker file, to connect to the server started via the CMD/ENTRYPOINT of the Dockerfile. As I'm guessing right now, the RUN occurs before the command is started.
Alternately, is there a Redis command or trick that would allow me to load some data into its database.
I suspect one approach would be to mount the Redis' data directory in a volume exposed to the Docker host; this is not ideal as
I would need an extra non-Dockerfile command to load the data
The loaded data would not be shared in the image, which is to be used by others on my team
I'm on OS X and am using docker-machine, so the volumes get trickier
The error tells Redis service is not started before you run redis-cli.
Add a new line to start it first. Let me know if this can fix your issue or not.
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN /usr/sbin/redis-server /etc/redis.conf
RUN redis-cli sadd production-stores 5555
Updates:
Review the official redis image, it has given the way to use redis-cli
# via redis-cli
$ docker run -it --link some-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
So I test the image and make it run as below:
# start redis container
$ docker run --name some-redis -d redis
# link redis container and run redis-cli command
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis
redis:6379> PING
PONG
redis:6379> exit
# Add the specified members to the set stored at key
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis sadd production-stores 5555
(integer) 1
$

How to run Redis on docker with a different configuration file?

I would like to set a password on my Redis server running on docker. I have followed the instcruction on https://registry.hub.docker.com/_/redis/:
1.I have created a folder with a Dockerfile containing:
FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
2.I have added a redis.conf file with:
requirepass thepassword
3.I built the image using:
docker build -t ouruser/redis .
4.I started the container:
docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes
The redis server does not have any password ! I do not understand why.
The run command:
docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes
Overrides the CMD defined in the Dockerfile with redis-server --appendonly yes, so your conf file will be being ignored. Just add the path to the conf file into your run command:
docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
Alternatively, set up an entrypoint script or add --appendonly yes to the CMD instruction.

docker rabbitmq hostname issue

I am build an image using Dockerfile, and I would like to add users to RabbitMQ right after installation. The problem is that during build hostname of the docker container is different from when I run the resultant image. RabbitMQ loses that user; because of changed hostname it uses another DB.
I connot change /etc/hosts and /etc/hostname files from inside a container, and looks that RabbitMQ is not picking my changes to RABBITMQ_NODENAME and HOSTNAME variables.
The only thing that I found working is running this before starting RabbitMQ broker:
echo "NODENAME=rabbit#localhost" >> /etc/rabbitmq/rabbitmq.conf.d/ewos.conf
But then I will have to run docker image with changed hostname all the time.
docker run -h="localhost" image
Any ideas on what can be done? Maybe the solution is to add users to RabbitMQ not on build but on image run?
Just here is example how to configure from Dockerfile properly:
ENV HOSTNAME localhost
RUN /etc/init.d/rabbitmq-server start ; rabbitmqctl add_vhost /test; /etc/init.d/rabbitmq-server stop
This is remember your config.
Yes, I would suggest to add users when the container runs for the first time.
Instead of starting RabbitMQ directly, you can run a wrapper script that will take care of all the setup, and then start RabbitMQ. If the last step of the wrapper script is a process start, remember that you can use exec so that the new process replaces the script itself.
This is how I did it.
Dockerfile
FROM debian:jessie
MAINTAINER Francesco Casula <fra.casula#gmail.com>
VOLUME ["/var/www"]
WORKDIR /var/www
ENV HOSTNAME my-docker
ENV RABBITMQ_NODENAME rabbit#my-docker
COPY scripts /root/scripts
RUN /bin/bash /root/scripts/os-setup.bash && \
/bin/bash /root/scripts/install-rabbitmq.bash
CMD /etc/init.d/rabbitmq-server start && \
/bin/bash
os-setup.bash
#!/bin/bash
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 my-docker" >> /etc/hosts
echo "my-docker" > /etc/hostname
install-rabbitmq.bash
#!/bin/bash
echo "NODENAME=rabbit#my-docker" > /etc/rabbitmq/rabbitmq-env.conf
echo 'deb http://www.rabbitmq.com/debian/ testing main' | tee /etc/apt/sources.list.d/rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add -
apt-get update
cd ~
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server_3.6.5-1_all.deb
dpkg -i rabbitmq-server_3.6.5-1_all.deb
apt-get install -f -y
/etc/init.d/rabbitmq-server start
sleep 3
rabbitmq-plugins enable amqp_client mochiweb rabbitmq_management rabbitmq_management_agent \
rabbitmq_management_visualiser rabbitmq_web_dispatch webmachine
rabbitmqctl delete_user guest
rabbitmqctl add_user bunny password
rabbitmqctl set_user_tags bunny administrator
rabbitmqctl delete_vhost /
rabbitmqctl add_vhost symfony_prod
rabbitmqctl set_permissions -p symfony_prod bunny ".*" ".*" ".*"
rabbitmqctl add_vhost symfony_dev
rabbitmqctl set_permissions -p symfony_dev bunny ".*" ".*" ".*"
rabbitmqctl add_vhost symfony_test
rabbitmqctl set_permissions -p symfony_test bunny ".*" ".*" ".*"
/etc/init.d/rabbitmq-server restart
IS_RABBIT_INSTALLED=`rabbitmqctl status | grep RabbitMQ | grep "3\.6\.5" | wc -l`
if [ "$IS_RABBIT_INSTALLED" = "0" ]; then
exit 1
fi
IS_RABBIT_CONFIGURED=`rabbitmqctl list_users | grep bunny | grep "administrator" | wc -l`
if [ "$IS_RABBIT_CONFIGURED" = "0" ]; then
exit 1
fi
Don't forget to run the container by specifying the right host with the -h flag:
docker run -h my-docker -it --name=my-docker -v $(pwd)/htdocs:/var/www my-docker
The only thing that helped me was to change default value in rabbitmq-env.conf of MNESIA_BASE property to MNESIA_BASE=/data and I added this command RUN mkdir /data in Dockerfile before starting server and add users.