LoginSignup
12
14

More than 5 years have passed since last update.

Docker pull commit push Dockerfile EC-CUBE3環境をつくる

Last updated at Posted at 2015-12-05

Dockerのインストール、pull、commit、push、Dockerfileからのbuildなど、一通りの事をEC-CUBE環境を作ることを目的にやってみましょう。

環境:VMWarePlayer or VirtualBoxの仮想マシン上にCentOS7.1を初期インストール

事前にDokerHubのアカウントを作成しておきましょう。

Apache:2.2.15
PHP:5.6.16
MySQL:5.1.73
EC-CUBE:3.0.6

Dockerのインストール

1.Dockerのインストール

コマンド
# yum -y install docker

2.Dockerの自動起動設定及びサービスの起動

コマンド
# systemctl enable docker.service
# systemctl start docker.service

3.コンテナーイメージへのディスク最適化設定追加

コマンド
# vi /etc/sysconfig/docker
OPTIONS='--selinux-enabled'
↓
OPTIONS='--selinux-enabled --storage-opt dm.no_warn_on_loop_devices=true'
:wq

4.Dockerサービスの再起動

コマンド
# systemctl restart docker.service

DockerfileからEC-CUBE環境作成

1.build用のディレクトリを作成

コマンド
# mkdir ~/build_eccube

2.Dockerfileを作成

コマンド
# cd build_eccube
# vi Dockerfile
Dockerfileのソースは事項参照
:wq
Dockerfile
#centos6のイメージを取得
FROM centos:centos6

#Dockerfile作成者
MAINTAINER linaction

#タイムゾーンの設定
RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

#yumによる必要パッケージのインストール
RUN yum -y install httpd mod_ssl mysql-server wget tar unzip

#yumリポジトリの追加
RUN rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#yumによる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

#tmpディレクトリに移動
WORKDIR /tmp/

#EC-CUBEファイルのダウンロード
RUN wget http://downloads.ec-cube.net/src/eccube-3.0.6.zip

#ダウンロードしたeccubeファイルの解凍
RUN unzip eccube-3.0.6.zip

#不要ファイルの削除
RUN rm -f ./eccube-3.0.6.zip

#eccubeディレクトリのリネーム
RUN mv eccube-3.0.6 eccube

#eccubeディレクトリのリネーム
RUN mv eccube /var/www/html

#eccubeディレクトリの権限変更
RUN chown -R apache:apache /var/www/html/eccube

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

#mysqldの起動、DB作成、ユーザ作成および権限設定、mysqldの停止
RUN service mysqld start && mysql -u root -e "CREATE DATABASE eccube_db; GRANT ALL PRIVILEGES ON eccube_db.* TO 'eccube'@'localhost' IDENTIFIED BY 'eccube123'; FLUSH PRIVILEGES;" && service mysqld stop

#mysqld,httpdの起動スクリプトの作成
RUN echo -e "service mysqld start\nservice httpd start\n/bin/bash" > /startService.sh

#mysqld,httpdの起動スクリプトの権限設定
RUN chmod o+x /startService.sh

#公開ポート
EXPOSE 80 443

#mysqld,httpdの起動スクリプトの実行
CMD /startService.sh

3.Dockerfileを実行

コマンド
# docker build -t DockerHubアカウント名/eccube:ver1.0 ~/build_eccube
・
・
Successfully built 0c4e45b86bcd

4.コンテナーを起動

コマンド
# docker run -itd -p 80:80 -p 443:443 --name eccube DockerHubアカウント名/eccube:ver1.0
3ce407416874308af370951ecf56c77b53e2aa405ba20aae51593fd3a0e2e108

コンテナーのcommit

1.ブラウザ確認

http://VirtualBoxのIPアドレス/」にアクセスし、eccubeの管理画面が表示されることを確認

2.コンテナーを停止

コマンド
# docker stop eccube

3.コンテナーを保存

コマンド
# docker commit eccube DockerHubアカウント名/eccube:ver1.0
cf75652d0f8a1509a5ad132ecf1214416c2b8dbf9fe9f93830ab8b51e738db73

4.コンテナーイメージを確認

コマンド
# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
DockerHubアカウント名/eccube          ver1.0              cf75652d0f8a        56 seconds ago      749.7 MB
docker.io/DockerHubアカウント名/centos   centos6             ce76491a3be1        2 hours ago         190.6 MB

コンテナーイメージをDocker Hubにpush

1.Docker Hubにログイン

コマンド
# docker login
Username:
Password:
Email:
Login Succeeded

2.Docker Hubにコンテナーイメージをpush

コマンド
# docker push DockerHubアカウント名/eccube
Do you really want to push to public registry? [y/n]: y
The push refers to a repository [docker.io/DockerHubアカウント名/eccube] (len: 0)
・
・
Digest: sha256:97e3bd8b7ed451163af7284513d398c426c796451d343400a9859156c1a8c021

3.リポジトリーを確認

コマンド
# docker search DockerHubアカウント名
INDEX       NAME                            DESCRIPTION               STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/DockerHubアカウント名/eccube

コンテナーイメージを再ダウンロード

最後に全てのイメージと停止コンテナを削除して、pushしたeccubeのコンテナーイメージをダウンロードして起動してみましょう。

1.停止コンテナの一括削除

コマンド
# docker rm `docker ps -a -q`
# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

2.イメージの一括削除

コマンド
# docker rmi イメージID
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

3.eccubeのコンテナーイメージをダウンロード

コマンド
# docker pull -a DockerHubアカウント名/eccube

4.コンテナーを起動

コマンド
# docker run -itd -p 80:80 -p 443:443 --name eccube DockerHubアカウント名/eccube:ver1.0

5.ブラウザ確認

http://VirtualBoxのIPアドレス/」にアクセスし、eccubeの管理画面が表示されることを確認

eccubeのMySQL情報
DB名:eccube_db
アカウント:eccube
パスワード:eccube123

12
14
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
12
14