This article is intended for those who can handle docker, python, uwsgi, and django to some extent as a single unit.
I want to create one application container as a docker container and deploy multiple applications in it.
It was realized by the following method.
./
├── Dockerfile
├── data
│ ├── hogehogeapp1
│ │ ├── hogehogeapp1
│ │ │ └──wsgi.py
│ │ ├── data
│ │ ├── db.sqlite3
│ │ └── manage.py
│ ├── hogehogeapp2
│ │ ├── hogehogeapp2
│ │ │ └──wsgi.py
│ │ ├── data
│ │ ├── db.sqlite3
│ │ └── manage.py
│ ├── hogehogeapp1.ini
│ └── hogehogeapp2.ini
└── init.sh
Dockerfile
FROM ubuntu:xenial #FROM ubuntu-xenial
MAINTAINER erscl
RUN apt-get -y update
RUN apt-get upgrade -yV
RUN apt-get update && apt-get install -y git gcc make openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev
RUN cd /usr/local &&\
git clone git://github.com/yyuu/pyenv.git ./pyenv &&\
mkdir -p ./pyenv/versions ./pyenv/shims &&\
cd /usr/local/pyenv/plugins/ &&\
git clone git://github.com/yyuu/pyenv-virtualenv.git
RUN echo 'export PYENV_ROOT="/usr/local/pyenv"' | tee -a /etc/profile.d/pyenv.sh
RUN echo 'export PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"' | tee -a /etc/profile.d/pyenv.sh
RUN export PYENV_ROOT="/usr/local/pyenv" &&\
export PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}" &&\
pyenv install -v 2.7.12 &&\
pyenv install -v 3.5.2 &&\
pyenv virtualenv 2.7.12 uwsgi-2.7 &&\
pyenv global uwsgi-2.7 &&\
pip install django==1.8.* django-bootstrap django-bootstrap-form django-registration uwsgi &&\
pyenv virtualenv 3.5.2 uwsgi-3.5 &&\
pyenv global uwsgi-3.5 &&\
pip install django django-bootstrap django-bootstrap-form uwsgi
RUN groupadd -g 1000 uwsgi && \
useradd -g uwsgi -m -s /bin/bash uwsgi
RUN mkdir -p /var/log/uwsgi && chown uwsgi /var/log/uwsgi
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY init.sh /opt/init.sh
EXPOSE 8801 8802
CMD ["/bin/bash","/opt/init.sh"]
init.sh
source /etc/profile.d/pyenv.sh
sudo -u uwsgi /usr/local/pyenv/versions/uwsgi-2.7/bin/uwsgi --ini /opt/data/hogehogeapp1.ini
sudo -u uwsgi /usr/local/pyenv/versions/uwsgi-3.5/bin/uwsgi --ini /opt/data/hogehogeapp2.ini
tail -f /dev/null
data/hogehogeapp1.ini
[uwsgi]
http=x1.x2.x3.x4:8801
chdir=/opt/data/hogehogeapp1
wsgi-file=/opt/data/hogehogeapp1/hogehogeapp1/wsgi.py
module=hogehogeapp.wsgi:application
master=True
pidfile=/var/run/hogehogeapp1.pid
vacuum=True
max-requests=5000
daemonize=/var/log/uwsgi/hogehogeapp1.log
data/hogehogeapp2.ini
[uwsgi]
http=x1.x2.x3.x4:8802
chdir=/opt/data/hogehogeapp2
wsgi-file=/opt/data/hogehogeapp2/hogehogeapp2/wsgi.py
module=hogehogeapp.wsgi:application
master=True
pidfile=/var/run/hogehogeapp2.pid
vacuum=True
max-requests=5000
daemonize=/var/log/uwsgi/hogehogeapp2.log
Add --volume / abs_path / data: / opt / data
when starting the container and start it
Recommended Posts