启动 redis-server 然后使用 bash

启动 redis-server 然后使用 bash
# Redis
    # Download and extract Redis source files
RUN curl -o redis.tar.gz "http://download.redis.io/releases/redis-4.0.2.tar.gz" && \
    mkdir redis_tmp/ && \
    tar xzf redis.tar.gz -C redis_tmp && \
    # Rename temporary directory
    mv redis_tmp/* redis && \
    # Install Redis
    cd redis && \
    make && \
    make install && \
    # Remove source files
    cd .. && \
    rm -rf redis && \
    # Confirm installation
    redis-server -v

# Cleanup
    # Remove local repository package files
RUN apt-get -y clean

ENTRYPOINT redis-server

CMD bash

这是我的 Dockerfile 的最后一部分。我想运行以下命令:

docker run -it test_image

我希望此图像启动 redis-server 并让我使用 bash。

但是它留给我redis-server:

kmorrison@Karl ~/dev/test_image (master) $ docker run -it test_image
9:C 06 Oct 10:09:23.266 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9:C 06 Oct 10:09:23.266 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=9, just started
9:C 06 Oct 10:09:23.266 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9:M 06 Oct 10:09:23.268 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9:M 06 Oct 10:09:23.268 # Server initialized
9:M 06 Oct 10:09:23.268 # 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.
9:M 06 Oct 10:09:23.268 * Ready to accept connections

它与 ENTRYPOINT 和 CMD 有关。

答案1

将以下行添加到您的 redis 配置中: daemonize yes或者使用它来redis-server --daemonize yes守护 Redis 服务。

或者,您可以从 systemd 或 upstart 启动 Redis。

更新: ENTRYPOINT redis-server --daemonize yes && bash事实证明,这是原始海报的有效解决方案。

答案2

这个问题很老了,但我通过搜索找到了它,所以我会提供答案。

您误解了图像中ENTRYPOINT和之间的关系。CMD

ENTRYPOINT是命令解释器,如果你愿意的话。它是执行指定命令的程序。当基于此映像的容器启动时,它将运行 < ENTRYPOINT> < CMD>。所以你说你想运行redis-server bash的,这不太可能达到你的预期。

虽然你可以自由地做ENTRYPOINT自己redis 服务器,不设置它会更正常。更自然的是,你可以将CMD redis-server镜像设置为守护进程并运行,然后根据需要执行它:

docker run --rm -d -p 6379:6379 --name redis my-image
docker exec -it redis bash

相关内容