Building production server on docker
- 6. Docker install
Introduction
Methods
Results
Discussion
● Docker
– http://docs.docker.com/installation/
● Docker-compose
– オーケストレーションツール
– http://docs.docker.com/compose/install/
$ wget -qO- https://get.docker.com/ | sh
$ curl -L
https://github.com/docker/compose/releases/download/1.1.0/docker-
compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
- 7. Docker つかうだけ
Introduction
Methods
Results
Discussion
● redmine を立ち上げる
– 準備するファイル : docker-compose.yml
$ docker-compose up -d
postgresql:
image: sameersbn/postgresql:9.4
environment:
- DB_USER=redmine
- DB_PASS=phatiphohsukeuwo
- DB_NAME=redmine_production
redmine:
image: sameersbn/redmine:3.0.1
links:
- postgresql:postgresql
environment:
- DB_USER=redmine
- DB_PASS=phatiphohsukeuwo
- DB_NAME=redmine_production
ports:
- "80:80"
- 12. 実例 :rbenv:ruby インストール
Introduction
Methods
Results
Discussion
#!/bin/bash
( いろいろ : 環境変数設定、ユーザ作成、 gem や Bundle のパス設定)
apt-get update
apt-get -y install build-essential curl ca-certificates
gcc g++ make bison libgdbm-dev ( いろいろ略)
rbenv install ${RUBY_VER}
rbenv global ${RUBY_VER}
gem update --system --no-document
gem install bundler --no-rdoc --no-ri
rbenv rehash
# cleanup
apt-get -y remove libgdbm-dev libncursesw5-dev libncurses5-dev
libreadline6-dev build-essential curl ( などなど、開発ファイルのみ)
apt-get clean
apt-get -y autoremove
- 16. kandan: install
Introduction
Methods
Results
Discussion
#!/bin/bash
( いろいろ : 環境変数設定、ユーザ作成、 gem や Bundle のパス設定)
apt-get update
apt-get -y install supervisor build-essential curl unzip git-core gcc
curl -sL https://deb.nodesource.com/setup | bash -
apt-get -y install nodejs
apt-get -y install sqlite3 libmysqlclient18 libmysqlclient-dev libsqlite3-dev
( いろいろ)
cat > ${KANDAN_CONF} <<__EOL__
[program:kandan]
command=${BUNDLE} exec thin start -e production
autostart=true
autorestart=false
username=${RUN_USER}
directory=${INSTALL_DIR}/kandan
stdout_logfile=${LOG_DIR}/%(program_name)s.log
stderr_logfile=${LOG_DIR}/%(program_name)s.log
environment=RBENV_ROOT=${RBENV_ROOT}
__EOL__
sudo -u ${RUN_USER} -E -H
git clone --depth 1 -b i18n --single-branch https://github.com/miurahr/kandan.git
- 17. kandan: install (cont.)
Introduction
Methods
Results
Discussion
# cleanup dev files
apt-get -y remove
unzip gcc g++ make curl git-core build-essential
libmysqlclient-dev libsqlite3-dev libpq-dev
libcurl4-openssl-dev libpcre3-dev libxml2-dev libxslt-dev
libreadline-gplv2-dev
# clean apt caches and more
apt-get clean
apt-get -y autoremove
find /var/lib/apt/lists/ -type f -exec rm -f {} ;
exit 0
- 18. kandan: init
Introduction
Methods
Results
Discussion
cat > ${INSTALL_DIR}/kandan/config/database.yml << __EOL1__
production:
adapter: mysql2
reconnect: false
timeout: 5000
database: ${DB_NAME}
host: ${DB_HOST}
port: ${DB_PORT}
pool: ${DB_POOL}
username: ${DB_USER}
password: ${DB_PASS}
__EOL1__
# start supervisord
exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
- 19. kandan: init (cont.)
Introduction
Methods
Results
Discussion
prog="mysqladmin -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USER}
${DB_PASS:+-p$DB_PASS} status"
timeout=60
echo -n "Waiting for database server to accept connections"
while ! ${prog} >/dev/null 2>&1
do
timeout=$(expr $timeout - 1)
if [ $timeout -eq 0 ]; then
echo -e "nCould not connect to database server. Aborting..."
exit 1
fi
echo -n "."
sleep 1
done
● コンテナから DBMS を同時に起動した場
合に、 DBMS の起動を待つ必要あり