【问题标题】:How to start redis server inside docker container如何在 docker 容器中启动 redis 服务器
【发布时间】:2019-10-25 20:35:33
【问题描述】:
FROM python:3.6

ENV PYTHONUNBUFFERED 1
WORKDIR /usr/src/consumerhub

COPY ./ /usr/src/consumerhub


RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs

RUN apt-get install -y redis-server
RUN systemctl start redis

RUN pip install -r requirements.txt
RUN npm install --prefix frontend/


CMD ["/bin/bash","-c","python manage.py runserver react 0.0.0.0:8000"]

我在 docker 容器中使用 redis。

我正在使用“systemctl start redis”在容器内启动 redis。 它是说 systemctl 不是命令。

注意:我不想使用 docker-compose 我必须在这里做。

请看一下

【问题讨论】:

  • 看看这个关于systemd和容器:systemd and systemctl within Ubuntu Docker images
  • 另外,Docker 文档"Run multiple services in a container" 建议在这种情况下使用像supervisord 这样的进程管理器。
  • @soubhagya pradhan 你可以检查一下,如果你发现任何问题,请告诉我
  • 安装redis时提示找不到apk命令
  • 你在使用我的 docker 文件吗? apk 适用于 alpine,不适用于 ubuntu 基础 docker 映像

标签: docker redis


【解决方案1】:

给你。容器启动后,您无需启动任何内容。一切都将在启动时开始。 我使用 Alpine 测试的一件事,而不是与 alpine 相比重的 python ubuntu。

为你的 python 应用修改注释的东西

FROM python:3.6-alpine
RUN mkdir -p /etc/supervisord.d

# general config for supervisord

RUN echo  $'[supervisord] \n\
[unix_http_server] \n\
file = /tmp/supervisor.sock \n\
chmod = 0777 \n\
chown= nobody:nogroup \n\
[supervisord] \n\
logfile = /tmp/supervisord.log \n\
logfile_maxbytes = 50MB \n\
logfile_backups=10 \n\
loglevel = info \n\ 
pidfile = /tmp/supervisord.pid \n\
nodaemon = true \n\
umask = 022 \n\
identifier = supervisor \n\
[supervisorctl] \n\
serverurl = unix:///tmp/supervisor.sock \n\
[rpcinterface:supervisor] \n\
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface \n\
[include] \n\
files = /etc/supervisord.d/*.conf' >> /etc/supervisord.conf

# starting redis-server using supervisor d

RUN echo $'[supervisord] \n\
nodaemon=true \n\
[program:redis] \n\
command=redis-server /etc/redis.conf \n\
autostart=true \n\
autorestart=true \n\
stdout_logfile=/var/log/redis/stdout.log \n\
stdout_logfile_maxbytes=0MB \n\ 
stderr_logfile=/var/log/redis/stderr.log \n\
stderr_logfile_maxbytes=10MB \n\
exitcodes=0 ' >> /etc/supervisord.d/redis.conf

# start your python script

RUN echo $'[supervisord] \n\
nodaemon=true \n\
[program:python-app] \n\
# command=python manage.py runserver react 0.0.0.0:8000\n\
command=python --version \n\
autorestart=unexpected \n\
stdout_logfile=/dev/fd/1 \n\
stdout_logfile_maxbytes=0MB \n\
stderr_logfile_maxbytes = 0 \n\
stderr_logfile=/dev/fd/2 \n\
redirect_stderr=true \n\
exitcodes=0 ' >> /etc/supervisord.d/python-app.conf



#installing requirement
RUN apk  add --no-cache supervisor  redis nodejs npm

# Your requried code etc

# ENV PYTHONUNBUFFERED 1
# WORKDIR /usr/src/consumerhub
# COPY ./ /usr/src/consumerhub
# RUN npm install --prefix frontend/
# RUN pip install -r requirements.txt


# allow external access
RUN sed -i '/protected-mode yes/c\protected-mode no ' /etc/redis.conf 

EXPOSE 6379 8000

ENTRYPOINT ["supervisord", "--nodaemon", "--configuration", "/etc/supervisord.conf"]

这是已安装软件包的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-16
    • 2014-09-02
    • 2018-12-14
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 2013-08-05
    • 2017-06-04
    相关资源
    最近更新 更多