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"]

I am using redis in docker container.

I am using "systemctl start redis" to start redis inside container. It is saying systemctl is not a command.

Note: I don't wants to use docker-compose i have to do it here.

Please have a look

  • Take a look at this about `systemd` and containers: [systemd and systemctl within Ubuntu Docker images](https://stackoverflow.com/questions/39169403/systemd-and-systemctl-within-ubuntu-docker-images) – tgogos Jun 11 '19 at 12:12
  • Also, Docker documentation ["Run multiple services in a container"](https://docs.docker.com/config/containers/multi-service_container/) proposes using a process manager like `supervisord` for such cases. – tgogos Jun 11 '19 at 12:16
  • @soubhagya pradhan you can check and let me know if you see any issue – Adiii Jun 12 '19 at 06:31
  • while installing redis it says apk command not found – soubhagya pradhan Jun 12 '19 at 08:42
  • are you using my docker file? apk is for alpine not for ubuntu base docker image – Adiii Jun 12 '19 at 08:53
  • I am using ubuntu based – soubhagya pradhan Jun 12 '19 at 08:54
  • you can use below posted docker image. which is light weight and having size of 200mb with all of the isntalled packages. – Adiii Jun 12 '19 at 09:13

1 Answers1

2

Here you go. You do not need to start anything after container up. Everything will be starting on bootup. And one thing I tested using Alpine, instead of python ubuntu which is heavy as compared to alpine.

Modify commented thing for your python app

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"]

Here is the list of installed packages.

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148