In my mind the master word of Docker is Fashion. So let's docker my blog ! It is a relativy a simple webapp, perfect for test Docker and micro-service architecture.
I won't make a new explanation of what are Docker and containers. For this kind of informations see the official doc. The great things I hold from this technology are:
- I can package my apps with Docker's image
- Fast configuration, deployment and spawning
- Simplyfing security with microservices
Dockerize my app
I considere my blog as a microservice, the containers which launch it will only serve uWSGI with my blog on port 3031. I began with a Dockerfile:
FROM python:2 # Create image from base python2.7 image
MAINTAINER Anthony MONTHE <anthony.monthe@gmail.com>
# Set variables
ENV PYTHONUNBUFFERED 1 # Disable stdout buffering
ENV uwsgi_ini /tmp/uwsgi.ini # uWSGI conf
ENV BLOG_CONFIG_FILE /tmp/myblog.cfg # MyBlog conf
ENV repo_dir /src/myblog # Repo path
ENV app_dir ${repo_dir}/myblog/ # Project path
# Mount files
ADD . $repo_dir # mount repo
ADD extras/docker/uwsgi.ini $uwsgi_ini
ADD extras/docker/myblog.cfg $BLOG_CONFIG_FILE
ADD extras/docker-entrypoint.sh /docker-entrypoint.sh # See below
RUN echo "chdir = $app_dir" >> $uwsgi_ini # Add project's path to uwsgi conf
# Install myblog
WORKDIR $repo_dir
RUN pip install -r requirements.txt
RUN pip install MySQL-Python uwsgi
RUN python setup.py install
# RUN myblog collectstatic --noinput
VOLUME /static # Shared static across containers and master
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["uwsgi", "--ini", "/tmp/uwsgi.ini"]
EXPOSE 3031 # Share uWSGI on 3031
With the file above and a docker build .
I created a docker image for my webapp.
Let's deploy it:
# docker run myblog uwsgi --ini /tmp/uwsgi.ini
[uWSGI] getting INI configuration from /tmp/uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Thu Jun 11 22:42:11 2015] ***
compiled with version: 4.9.2 on 20 May 2015 16:59:24
os: Linux-3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24)
nodename: 2e5c1c53916d
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /src/myblog
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /src/myblog/myblog/
your processes number limit is 3919
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:3031 fd 3
Python version: 2.7.9 (default, May 20 2015, 08:25:59) [GCC 4.9.2]
Python main interpreter initialized at 0x7343a0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 218304 bytes (213 KB) for 2 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x7343a0 pid: 1 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1)
spawned uWSGI worker 1 (pid: 8, cores: 1)
spawned uWSGI worker 2 (pid: 9, cores: 1)
You'll have a containerized instance of myblog. This installation isn't complete, several things are missing:
- There's no database
- No cache too
- It isn't an HTTP server, you must add a frontend as Nginx or Apache for use it with WSGI protocol
Next step is make a full stack install with docker-compose.
Comments