0

I am trying to connect to redis containers together to share some data, but I'm not having much luck. First I create a new docker container:

➜  docker-react git:(master) ✗ docker run -d --name red1 -v ~/vol:/data redis
7cec6f4fce354c3c603ef36813d9b8f41b446278b76bc8f05a901980bb864241
➜  docker-react git:(master) ✗ docker run -d --name red2 -v ~/vol:/data redis
566d4728cd8d2548a1ba4631bb118699157e03aae32a4566370fafdfae93463d
➜  docker-react git:(master) ✗ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
566d4728cd8d        redis               "docker-entrypoint.s…"   9 seconds ago       Up 8 seconds        6379/tcp            red2
7cec6f4fce35        redis               "docker-entrypoint.s…"   20 seconds ago      Up 19 seconds       6379/tcp            red1

But when I go into 1 container and set some data, for example:

➜  docker-react git:(master) ✗ docker exec -it 566d4728cd8d redis-cli
127.0.0.1:6379> SET name Jim
OK
127.0.0.1:6379> SET age 20
OK
127.0.0.1:6379> get name
"Jim"
127.0.0.1:6379>

and then I go into the 2nd container, it is oblivious to the data:

➜  docker-react git:(master) ✗ docker exec -it 7cec6f4fce35 redis-cli
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379>

Why? How can I connect these 2 containers to share the same data?

lkdjf0293
  • 55
  • 6

1 Answers1

0

For me it looks like you are just launching two container of redis using the same volume. Have you setup those instances to store the data at the volumes location?

Kevin Klinger
  • 93
  • 1
  • 4
  • How do you do that? – lkdjf0293 Apr 10 '19 at 15:03
  • The dump is written to /data within the container. To start redis using a config file have a look at: [23498203](https://stackoverflow.com/questions/23496546/start-redis-server-with-config-file/). But I think it's more likely you want a master slave setup which replicates the data between your instances. You can set this up as described in: [configure redis master slave setup](https://linuxtechlab.com/configuring-redis-master-slave-setup/). For further information about replication look at: [redis replication](https://redis.io/topics/replication) – Kevin Klinger Apr 11 '19 at 08:04