项目结构:
mysql:
conf.d
start.sh:
#!/bin/bash
#
echo "---------------start mysql image-------------------"
docker run --name mysql \
-v $(pwd)/conf.d:/etc/mysql/conf.d \
-v $(pwd)/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=mysql \
-p 3307:3306 \
-d daocloud.io/mysql:5.7.20 \
--character-set-server=utf8 --collation-server=utf8_unicode_ci
#sleep 15
my.cnf:
character.cnf:
Nginx:
start.sh:
#!/bin/bash
#
docker build -t nginx .
docker run --name nginx-server \
--link django:web \
-v /mysite/mysite/static:/www/static \
--volumes-from django \
-p 80:80 \
-d nginx
dockerfile:
FROM daocloud.io/nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD nginx-conf/ /etc/nginx/conf.d/
restart.sh stop.sh 请参考项目源码 https://github.com/wangguanfu/docker.sh
web(django):
dockerfile:
# 基础镜像
FROM daocloud.io/python:2.7
ENV DJANGO_PRODUCTION false
RUN mkdir /mysite
ADD . /mysite
# app 所在目录
WORKDIR /mysite
# 安装 app 所需依赖
RUN pip install --no-cache-dir -r /mysite/mysite/requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
start.sh:
#!/bin/bash
#
docker exec -d mysql mysql -uroot -pmysql -e "create database blog;"
docker build -t mysite/django .
docker run --name django \
-v /mysite \
-v /mysite/static \
--link mysql:mysql \
-p 8000:8000 \
-d mysite/django /usr/local/bin/uwsgi --http :8000 --chdir /mysite/mysite -w mmcsite.wsgi
init_django.sh:
#!/bin/bash
#
echo '---------------migrate database main------------------------'
docker exec -it django python /mysite/mysite/manage.py migrate
echo '---------------create superuser admin-----------------------'
docker exec -it django python /mysite/mysite/manage.py createsuperuser --username admin --email admin@admin.com --database default
更多细节参考源码 :https://github.com/wangguanfu/docker.sh