LoginSignup
3
4

More than 5 years have passed since last update.

docker-composeを使ってec-cube3環境を構築

Last updated at Posted at 2016-07-11

概要

今更ながら、Docker環境にec-cube3をインストールしてみた。
Docker pull commit push Dockerfile EC-CUBE3環境をつくる
を参考にし、CentOS7上に乗せてみた。
昔と比べて色々ディストリビューションもUpgradeされていて、Dockerと関係ない箇所で躓いたりしていたので
備忘録的に記載します。

環境

まずは1コンテナに以下をインストールする。
Apache 及び MySQLは現時点でのDefaultで、Version指定はしていない。
- HostOS:CentOS7(Vagrantを使用)
- GuestOS:CentOS7
- Mysql:5.7.13
- PHP:5.6
- Apache:2.4.6
- EC-CUBE:3.10

ファイル構成

root/
 └ centos7-default/
   └ Dockerfile
 └ centos7/
   └ Dockerfile
 └ eccube/
   └ boot.sh
 └ docker-compose.yml

インストール方法

docker-composeをHost OSにインストール

省略

CentOS7周りの設定

DefaultではSystemdでは動かないので

を参考に

centos7-default/Dockerfile

FROM centos:centos7

MAINTAINER hiabe
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; \
for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*; \
yum update -y; \
# 後でMySQLをインストールするためここでWGET,EPEL,Remiを追加
yum install -y wget epel-release; \ 
cd /etc/yum.repos.d; \
wget http://rpms.famillecollet.com/enterprise/remi.repo; 

VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

でとりあえずこれを

docker build --rm -t hiabe/centos7-systemd

として一旦保存し、

centos7/Dockerfile
FROM hiabe/centos7-systemd

MAINTAINER hiabe
RUN yum -y install httpd mod_ssl \
&&  yum localinstall -y http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm \
&&  yum -y install mysql-community-server
#RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

#Install php5.6
RUN yum install -y --enablerepo=remi --enablerepo=remi-php56 php php-common php-mbstring php-gd php-xml php-xmlrpc php-devel php-cli php-pdo php-pgsql php-mysql php-odbc php-pear php-mcrypt php-pecl-apc

#Install composer
#RUN curl -sS https://getcomposer.org/installer | php \
#&& mv composer.phar /usr/local/bin/composer

#set the files for EC-CUBE
WORKDIR /tmp/
RUN yum -y install unzip \
&& wget http://downloads.ec-cube.net/src/eccube-3.0.10.zip \
&& unzip eccube-3.0.10.zip \
&& rm -f eccube-3.0.10.zip \
&& mv eccube-3.0.10 /var/www/html/ec-cube \
&& chown -R apache:apache /var/www/html/ec-cube

#httpd.conf
RUN sed -i -e 's#DocumentRoot "/var/www/html"#DocumentRoot "/var/www/html/ec-cube/html"#g' -e 's#<Directory "/var/www/html">#<Directory /var/www/html/ec-cube/html">#g' -e 's#Options Indexes FollowSymLinks#Options -Indexes +FollowSymLinks#g' -e 's#AllowOverride None#AllowOverride All#g' /etc/httpd/conf/httpd.conf

#mysqld
RUN systemctl enable mysqld.service \
&& systemctl enable httpd.service

EXPOSE 80 443

#mysqld,httpdの起動スクリプトの実行
CMD ["/usr/sbin/init"]

そしてこれを起動する。私はdocker-composeを使って起動、Installについては省略

docker-compose.yml
centos7:
  build: centos7/
  ports:
    - 8080:80
  container_name: centos7d
  privileged: true
docker-compose up -d

MySQLは現時点ではdefault install であるため、root passwordをログより取得する。

docker exec -it centos7d /bin/bash

[root@946674c53ed1 tmp]# cat /var/log/mysqld.log|grep 'password is generated'
2016-07-08T02:54:35.453152Z 1 [Note] A temporary password is generated for root@localhost: /H%_)2o+LkU(
exit

こんな感じなので、以下のようなshellを用意する。
こちらにあるようにPasswordのPolicyが変更されているようなので注意が必要

eccube/boot.sh
#!/bin/bash
localectl set-locale LANG=ja_JP.UTF-8
echo 'run /usr/sbin/init'
/usr/sbin/init
echo `ls -l /var/log/mysqld.log`
echo `cat /var/log/mysqld.log |grep 'A temporary password is generated' `
MYSQLPASS=`cat /var/log/mysqld.log |grep 'A temporary password is generated '|sed 's/\(.*\)localhost\: //g'`
MYSQLNEWPASS='rootP@ss01'
ECCUBEPASS='eccubeP@ss01'
#changed root password
/usr/bin/mysql -u root -p$MYSQLPASS --connect-expired-password -e "ALTER USER root@localhost IDENTIFIED BY \"$MYSQLNEWPASS\""
echo "Changed root password"
#create user for EC-CUBE
/usr/bin/mysql -u root -p$MYSQLNEWPASS --connect-expired-password -e "CREATE DATABASE IF NOT EXISTS eccube_db; GRANT ALL PRIVILEGES ON eccube_db.* TO 'eccube'@'localhost' IDENTIFIED BY \"$ECCUBEPASS\"; FLUSH PRIVILEGES;"

docker-compose.ymlの修正(command を overwrite)

docker-compose.yml
centos7:
  build: centos7/
  ports:
    - 8080:80
  volume:
    - ./eccube:/tmp/eccube
  container_name: centos7d
  privileged: true
  command: /bin/bash /tmp/eccube/boot.sh

エラー発生

docker-compose up
.....
centos7d | Couldn't find an alternative telinit implementation to spawn.
.....

問題回避

現時点では解決方法がわからないので、仕方なく起動後にshellを実行する。
commandをコメントアウト。

docker-compose.yml
centos7:
  build: centos7/
  ports:
    - 8080:80
  volume:
    - ./eccube:/tmp/eccube
  container_name: centos7d
  privileged: true
# docker run 後に以下のshellを実行
# command: /bin/bash /tmp/eccube/boot.sh 

boot.sh起動によるDB周りの設定

docker-compose stop
docker-compose build
docker-compose up -d
docker exec -it centos7d /bin/bash

[root@946674c53ed1 tmp]# sh /tmp/ec-cube/boot.sh

#新rootpasswordでログイン

mysql>exit

#今度はeccube用のDBへ接続、同じくログインできればOK
/usr/bin/mysql -u eccube -peccubeP@ss01 eccube_db

mysql>exit

動作確認

http://192.168.33.10:8080/install.php
にて問題なく画面が表示されればOK

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4