Last active
August 21, 2016 18:49
-
-
Save james-m/8700237 to your computer and use it in GitHub Desktop.
RedisMasterSlaveOnDocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ cat base/2.8.1/Dockerfile | |
FROM ubuntu:12.10 | |
MAINTAINER James McKernan [email protected] | |
RUN apt-get update | |
RUN apt-get install -y build-essential | |
ADD redis-2.8.1.tar.gz redis-2.8.1.tar.gz | |
RUN tar xvfz redis-2.8.1.tar.gz | |
RUN cd redis-2.8.1 && make | |
RUN cd redis-2.8.1 && make install | |
# | |
# build: docker build -t jamesm/redis-base:2.8.1 . | |
# run: docker run -i -t jamesm/redis-base:2.8.1 /bin/bash | |
# (cli) docker run -link=redis0:redis -i -t -name=redis-cli jamesm/redis-base /bin/bash | |
# | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### In the slave cli container here | |
172.17.0.29:6379> keys * | |
1) "hello" | |
172.17.0.29:6379> | |
###### ^P^Q here, then attach the master cli | |
vagrant@ubuntu-12:/docker-pub/redis$ | |
vagrant@ubuntu-12:/docker-pub/redis$ docker attach redis-cli | |
172.17.0.27:6379> keys * | |
1) "hello" | |
172.17.0.27:6379> set MOAR data | |
OK | |
172.17.0.27:6379> | |
###### Another ^P^Q, then back into the slave cli | |
vagrant@ubuntu-12:/docker-pub/redis$ | |
vagrant@ubuntu-12:/docker-pub/redis$ docker attach redis-slave-cli | |
172.17.0.29:6379> keys * | |
1) "hello" | |
2) "MOAR" | |
172.17.0.29:6379> get MOAR | |
"data" | |
172.17.0.29:6379> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker attach redis-cli | |
172.17.0.27:6379> | |
172.17.0.27:6379> info replication | |
# Replication | |
role:master | |
connected_slaves:1 | |
slave0:ip=172.17.0.29,port=6379,state=online,offset=491,lag=0 | |
master_repl_offset:491 | |
repl_backlog_active:1 | |
repl_backlog_size:1048576 | |
repl_backlog_first_byte_offset:2 | |
repl_backlog_histlen:490 | |
172.17.0.27:6379> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker run -link=redis0_slave:redis -i -t -name=redis-slave-cli jamesm/redis-base /bin/bash | |
root@95f3cb4b128a:/# redis-cli -h $REDIS_PORT_6379_TCP_ADDR -p $REDIS_PORT_6379_TCP_PORT | |
172.17.0.29:6379> keys * | |
1) "hello" | |
172.17.0.29:6379> info replication | |
# Replication | |
role:slave | |
master_host:172.17.0.27 | |
master_port:6379 | |
master_link_status:up | |
master_last_io_seconds_ago:6 | |
master_sync_in_progress:0 | |
slave_repl_offset:1807 | |
slave_priority:100 | |
slave_read_only:1 | |
connected_slaves:0 | |
master_repl_offset:0 | |
repl_backlog_active:0 | |
repl_backlog_size:1048576 | |
repl_backlog_first_byte_offset:0 | |
repl_backlog_histlen:0 | |
172.17.0.29:6379> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker images jamesm/redis* | |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | |
jamesm/redis-slave 2.6.16 62d236e34da2 About a minute ago 509.8 MB | |
jamesm/redis-standalone 2.6.16 28e7f2c6c9e7 About a minute ago 509.8 MB | |
jamesm/redis-standalone 2.8.1 4829a569c16b About a minute ago 509.8 MB | |
jamesm/redis-standalone latest 4829a569c16b About a minute ago 509.8 MB | |
jamesm/redis-slave 2.8.1 34d380b6dc45 About a minute ago 509.8 MB | |
jamesm/redis-slave latest 34d380b6dc45 About a minute ago 509.8 MB | |
jamesm/redis-base 2.8.1 dbd82d191860 About a minute ago 509.8 MB | |
jamesm/redis-base latest dbd82d191860 About a minute ago 509.8 MB | |
jamesm/redis-base 2.6.16 37a29a3d26c9 2 minutes ago 508.6 MB | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker logs redis0 | |
[1] 29 Jan 17:56:15.375 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984. | |
_._ | |
_.-``__ ''-._ | |
_.-`` `. `_. ''-._ Redis 2.8.1 (00000000/0) 64 bit | |
.-`` .-```. ```\/ _.,_ ''-._ | |
( ' , .-` | `, ) Running in stand alone mode | |
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | |
| `-._ `._ / _.-' | PID: 1 | |
`-._ `-._ `-./ _.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | http://redis.io | |
`-._ `-._`-.__.-'_.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | | |
`-._ `-._`-.__.-'_.-' _.-' | |
`-._ `-.__.-' _.-' | |
`-._ _.-' | |
`-.__.-' | |
[1] 29 Jan 17:56:15.376 # Server started, Redis version 2.8.1 | |
[1] 29 Jan 17:56:15.376 * The server is now ready to accept connections on port 6379 | |
[1] 29 Jan 18:30:00.405 * Slave asks for synchronization | |
[1] 29 Jan 18:30:00.405 * Full resync requested by slave. | |
[1] 29 Jan 18:30:00.405 * Starting BGSAVE for SYNC | |
[1] 29 Jan 18:30:00.405 * Background saving started by pid 9 | |
[9] 29 Jan 18:30:00.407 * DB saved on disk | |
[9] 29 Jan 18:30:00.407 * RDB: 0 MB of memory used by copy-on-write | |
[1] 29 Jan 18:30:00.486 * Background saving terminated with success | |
[1] 29 Jan 18:30:00.487 * Synchronization with slave succeeded | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
20f29b34bf53 jamesm/redis-base:2.8.1 /bin/bash About a minute ago Up About a minute redis-cli | |
90e103877623 jamesm/redis-standalone:2.8.1 /usr/local/bin/redis 12 minutes ago Up 12 minutes 0.0.0.0:49154->6379/tcp redis-cli/redis,redis0 | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker run -rm -i -t jamesm/redis-base /bin/bash | |
root@b52a2808ec6b:/# redis-server | |
[9] 29 Jan 17:16:29.004 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf | |
[9] 29 Jan 17:16:29.005 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984. | |
_._ | |
_.-``__ ''-._ | |
_.-`` `. `_. ''-._ Redis 2.8.1 (00000000/0) 64 bit | |
.-`` .-```. ```\/ _.,_ ''-._ | |
( ' , .-` | `, ) Running in stand alone mode | |
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | |
| `-._ `._ / _.-' | PID: 9 | |
`-._ `-._ `-./ _.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | http://redis.io | |
`-._ `-._`-.__.-'_.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | | |
`-._ `-._`-.__.-'_.-' _.-' | |
`-._ `-.__.-' _.-' | |
`-._ _.-' | |
`-.__.-' | |
[9] 29 Jan 17:16:29.007 # Server started, Redis version 2.8.1 | |
[9] 29 Jan 17:16:29.007 * The server is now ready to accept connections on port 6379 | |
^C | |
root@b52a2808ec6b:/# exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker run -link=redis0:redis -i -t -name=redis-cli jamesm/redis-base:2.8.1 /bin/bash | |
root@20f29b34bf53:/# env | |
REDIS_PORT_6379_TCP_PROTO=tcp | |
HOSTNAME=20f29b34bf53 | |
TERM=xterm | |
REDIS_NAME=/redis-cli/redis | |
REDIS_PORT_6379_TCP_ADDR=172.17.0.27 | |
REDIS_PORT_6379_TCP_PORT=6379 | |
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
PWD=/ | |
REDIS_PORT_6379_TCP=tcp://172.17.0.27:6379 | |
SHLVL=1 | |
REDIS_PORT=tcp://172.17.0.27:6379 | |
HOME=/ | |
container=lxc | |
_=/usr/bin/env | |
root@20f29b34bf53:/# redis-cli -h $REDIS_PORT_6379_TCP_ADDR -p $REDIS_PORT_6379_TCP_PORT | |
172.17.0.27:6379> set hello world | |
OK | |
172.17.0.27:6379> get hello | |
"world" | |
172.17.0.27:6379> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker run -d -P -name=redis0_slave -link=redis0:redis_master jamesm/redis-slave | |
68888b1831916069bbb29a00a6d16727efa8d21275c794c1523017844c7fc1e6 | |
vagrant@ubuntu-12:/docker-pub/redis$ docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
68888b183191 jamesm/redis-slave:2.8.1 ./start-slave.sh --d 3 seconds ago Up 3 seconds 0.0.0.0:49155->6379/tcp redis0_slave | |
20f29b34bf53 jamesm/redis-base:2.8.1 /bin/bash 23 minutes ago Up 23 minutes redis-cli | |
90e103877623 jamesm/redis-standalone:2.8.1 /usr/local/bin/redis 33 minutes ago Up 33 minutes 0.0.0.0:49154->6379/tcp redis-cli/redis,redis0,redis0_slave/redis_master | |
vagrant@ubuntu-12:/docker-pub/redis$ docker logs redis0_slave | |
[1] 29 Jan 18:30:00.402 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984. | |
_._ | |
_.-``__ ''-._ | |
_.-`` `. `_. ''-._ Redis 2.8.1 (00000000/0) 64 bit | |
.-`` .-```. ```\/ _.,_ ''-._ | |
( ' , .-` | `, ) Running in stand alone mode | |
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | |
| `-._ `._ / _.-' | PID: 1 | |
`-._ `-._ `-./ _.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | http://redis.io | |
`-._ `-._`-.__.-'_.-' _.-' | |
|`-._`-._ `-.__.-' _.-'_.-'| | |
| `-._`-._ _.-'_.-' | | |
`-._ `-._`-.__.-'_.-' _.-' | |
`-._ `-.__.-' _.-' | |
`-._ _.-' | |
`-.__.-' | |
[1] 29 Jan 18:30:00.402 # Server started, Redis version 2.8.1 | |
[1] 29 Jan 18:30:00.402 * The server is now ready to accept connections on port 6379 | |
[1] 29 Jan 18:30:00.404 * Connecting to MASTER 172.17.0.27:6379 | |
[1] 29 Jan 18:30:00.404 * MASTER <-> SLAVE sync started | |
[1] 29 Jan 18:30:00.404 * Non blocking connect for SYNC fired the event. | |
[1] 29 Jan 18:30:00.404 * Master replied to PING, replication can continue... | |
[1] 29 Jan 18:30:00.405 * Partial resynchronization not possible (no cached master) | |
[1] 29 Jan 18:30:00.405 * Full resync from master: 478f688e6fc61b11d8ef8cb2570592156464c28a:1 | |
[1] 29 Jan 18:30:00.487 * MASTER <-> SLAVE sync: receiving 33 bytes from master | |
[1] 29 Jan 18:30:00.487 * MASTER <-> SLAVE sync: Loading DB in memory | |
[1] 29 Jan 18:30:00.487 * MASTER <-> SLAVE sync: Finished with success | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ docker run -d -P -v ~/data/redis0:/data -name=redis0 jamesm/redis-standalone | |
90e1038776239bebfe9e1be7500d31a9485165bef5f44da7b072c5eff469540e | |
vagrant@ubuntu-12:/docker-pub/redis$ docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
90e103877623 jamesm/redis-standalone:2.8.1 /usr/local/bin/redis 7 seconds ago Up 6 seconds 0.0.0.0:49154->6379/tcp redis0 | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ cat slave/Dockerfile | |
FROM jamesm/redis-base:latest | |
EXPOSE 6379 | |
VOLUME ["/data"] | |
RUN sysctl vm.overcommit_memory=1 | |
ADD start-slave.sh start-slave.sh | |
ENTRYPOINT ["./start-slave.sh", "--dir", "/data"] | |
# | |
# build: docker build -t jamesm/redis-slave . | |
# run: docker run -d -P -name=redis0_slave -link=redis0:redis_master jamesm/redis-slave | |
# | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ cat slave/start-slave.sh | |
#!/bin/bash | |
# | |
if [ -z "$REDIS_MASTER_PORT_6379_TCP_ADDR" ]; then | |
echo "REDIS_MASTER_PORT_6379_TCP_ADDR not defined. Did you run with -link?"; | |
exit 7; | |
fi | |
# exec allows redis-server to receive signals for clean shutdown | |
# | |
exec /usr/local/bin/redis-server --slaveof $REDIS_MASTER_PORT_6379_TCP_ADDR $REDIS_MASTER_PORT_6379_TCP_PORT $* | |
vagrant@ubuntu-12:/docker-pub/redis$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-12:/docker-pub/redis$ cat standalone/Dockerfile | |
FROM jamesm/redis-base:latest | |
EXPOSE 6379 | |
VOLUME ["/data"] | |
RUN sysctl vm.overcommit_memory=1 | |
ENTRYPOINT ["/usr/local/bin/redis-server", "--dir", "/data"] | |
# | |
# build: docker build -t jamesm/redis-standalone . | |
# run: docker run -d -P -v ~/data/redis0:/data -name=redis0 jamesm/redis-standalone | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment