如何在 Docker 容器中启动 Redis 服务器

3
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 和容器的内容:Ubuntu Docker 镜像中的 systemd 和 systemctl - tgogos
此外,Docker文档"在容器中运行多个服务"建议在这种情况下使用进程管理器,如supervisord - tgogos
@soubhagya pradhan,您可以检查并让我知道是否有任何问题。 - Adiii
我正在使用基于Ubuntu的操作系统。 - soubhagya pradhan
你可以使用下面发布的 Docker 镜像。它体积轻盈,大小为200MB,包含所有已安装的软件包。 - Adiii
显示剩余2条评论
1个回答

2

这是你需要的答案。启动容器后无需启动任何内容,一切都将在启动时开始运行。我测试过使用Alpine而不是Python Ubuntu,因为相比于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"]

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

这是图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接