LoginSignup
14
13

More than 5 years have passed since last update.

Docker用LAMPコンテナー

Last updated at Posted at 2016-03-24

以下の環境構築をすばやくできるDockerコンテナーを作成する為のメモ。

  • Apache 2.2系
  • PHP 5.5系
  • MySQL 5.6系
  • phpMyAdmin

用意するもの

  • dockerがインストールされた環境(本手順ではバージョン1.8)
  • Dockerfile
  • httpd.conf (初期設定で良ければ無くてもOK)
  • my.cnf (初期設定で良ければ無くてもOK)
  • supervisord.conf

Dockerfile

Dockerfile
FROM centos:centos6

RUN sed -i '/^ZONE/d' /etc/sysconfig/clock
RUN sed -i '/^UTC/d' /etc/sysconfig/clock
RUN echo 'ZONE="Asia/Tokyo"' >> /etc/sysconfig/clock
RUN echo 'UTC="false"' >> /etc/sysconfig/clock
RUN cp -p /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

RUN yum -y update

RUN yum -y groupinstall "Japanese Support"
RUN localedef -f UTF-8 -i ja_JP ja_JP.utf8
RUN echo 'LANG="ja_JP.UTF-8"' > /etc/sysconfig/i18n

RUN yum -y install python-setuptools
RUN easy_install supervisor

RUN yum install -y http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
RUN yum install -y mysql mysql-server mysql-devel

RUN rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
RUN yum install -y httpd httpd-devel
RUN yum install -y --enablerepo=remi,remi-php55 phpMyAdmin
RUN yum install -y --enablerepo=epel libmcrypt
RUN yum install -y --enablerepo=remi,remi-php55 php php-devel php-pear php-mbstring php-xml php-mcrypt php-gd php-pecl-xdebug php-opcache php-pecl-apcu php-fpm php-phpunit-PHPUnit php-mysqlnd

RUN rm -f /etc/httpd/conf.d/welcome.conf
RUN rm -f /var/www/error/noindex.html
ADD httpd.conf /etc/httpd/conf/httpd.conf

ADD my.cnf /etc/my.cnf

ADD supervisord.conf /etc/supervisord.conf

EXPOSE 3306 80
CMD ["/usr/bin/supervisord"]

httpd.conf

良さ気なものを用意

my.cnf

良さ気なものを用意

supervisord.conf

supervisord.conf
[supervisord]
nodaemon=true

[program:mysqld]
command=/sbin/service mysqld start

[program:httpd]
command=/sbin/service httpd start

ビルド

lampディレクトリに用意したものを全て入れたとする。

$ cd lamp
$ sudo docker build -t lamp .

起動

$ sudo docker run -d -p 80:80 lamp

開発時に便利な初期設定

コンテナーにbashで入る。

$ sudo docker exec -it [コンテナー名] bash

とりあえず開発ツールを入れておく。

$ yum -y group install "Development tools"

ビルド時に入れてないのは、imageの容量が大きくなってしまうので。。。

gitに用意した

「必要なもの」項目に該当するものをgitに用意した。
cloneすればどの環境でも呼び出せる!

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