Docker安装RabbitMQ(docker-compose.yml)
 

前置条件

请先安装Docker 

 

创建docker-compose.yml文件

version: '2'
services:

  #redis容器
  redis:
    #定义主机名
    hostname: myredis
    #使用的镜像
    image: redis:5.0.2
    #容器的映射端口
    ports:
      - 6381:6379
    restart: always
    #定义挂载点
    volumes:
      - ./redis/data:/data
    #环境变量
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8

将以上文件保存为docker-compose.yml文件

 

启动docker-compose脚本

docker-compose up

 

启动日志

AppledeMacBook-Pro:~ apple$ cd ~/Docker/Workspace/
AppledeMacBook-Pro:Workspace apple$ ls
activemq	rabbitmq
AppledeMacBook-Pro:Workspace apple$ mkdir redis
AppledeMacBook-Pro:Workspace apple$ cd redis/
AppledeMacBook-Pro:redis apple$ ls
AppledeMacBook-Pro:redis apple$ vim docker-compose.yml
AppledeMacBook-Pro:redis apple$ docker-compose up
Creating network "redis_default" with the default driver
Pulling redis (redis:5.0.2)...
5.0.2: Pulling from library/redis
a5a6f2f73cd8: Pull complete
a6d0f7688756: Pull complete
53e16f6135a5: Pull complete
b761e99e9c9c: Pull complete
13686b3f2e29: Pull complete
667e8fd02be2: Pull complete
Creating redis_redis_1 ... done
Attaching to redis_redis_1
redis_1  | 1:C 16 Apr 2019 14:57:30.990 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 16 Apr 2019 14:57:30.992 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 16 Apr 2019 14:57:30.992 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 16 Apr 2019 14:57:30.993 * Running mode=standalone, port=6379.
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # Server initialized
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1  | 1:M 16 Apr 2019 14:57:30.994 * Ready to accept connections
redis_1  | 1:M 16 Apr 2019 14:59:16.765 * DB saved on disk
redis_1  | 1:M 16 Apr 2019 14:59:28.481 * DB saved on disk

 

Redis命令行

AppledeMacBook-Pro:~ apple$ redis-cli -h 127.0.0.1 -p 6381
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> keys
(error) ERR wrong number of arguments for 'keys' command
127.0.0.1:6381> keys *
(empty list or set)
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> flushall
OK

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐