LoginSignup
8
11

More than 5 years have passed since last update.

レガシーな開発環境(PHP5.3、Oracle、CentOS5.1)をDockerで作った

Last updated at Posted at 2016-11-07

多分、この記事は誰の役にも立たないです。

なぜなら、2016年11月現在で、こんなレガシーな環境は少ないだろうからです。

とはいえ、誰かの役に立つかもしれないので記載しておきます。もっといいやり方があれば教えて下さい。

下記の環境を構築しました。

  • PHP 5.3
  • Oracle(クライアントのみ、11g)
  • CentOS 5.1

PHP拡張として下記を入れています。

  • PHP-Redis
  • APC

ファイルの全体はこんな感じ。Redisは割愛。

.
|-- docker-compose.yml
|-- app/(以下ソースコード)
`-- web/
    |-- Dockerfile
    |-- httpd.conf
    |-- oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
    |-- oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
    |-- oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
    `-- php.ini

Docker composeはこれ

docker-compose.yml
version: '2'
services:
  web:
    build: ./web
    ports:
      - "8000:80"
    links:
      - redis
    volumes:
      - ./app:/home/www/html
  redis:
    build: ./redis

肝心のWebイメージ用Dockerfile

web/Dockerfile
FROM centos:5

RUN yum -y update && yum -y upgrade
RUN yum -y install wget curl make gcc autoconf \
                   libaio libaio-devel libxml2-devel libjpeg-devel libpng-devel curl-devel

# Install apache
RUN useradd apache
RUN cd /tmp && \
    wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/httpd/httpd-2.2.31.tar.gz && \
    tar zxf httpd-2.2.31.tar.gz
RUN cd /tmp/httpd-2.2.31 && \
    ./configure --enable-so && make && make install
COPY httpd.conf /usr/local/apache2/conf

# Install oracle client
COPY oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm /tmp
COPY oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm /tmp
COPY oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm /tmp

RUN rpm -ivh /tmp/oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm && \
    rpm -ivh /tmp/oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm && \
    rpm -ivh /tmp/oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

ENV TNS_ADMIN /
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/lib/oracle/11.2/client64/lib/
ENV NLS_LANG Japanese_Japan.AL32UTF8
ENV NLS_DATE_FORMAT 'YYYY/MM/DD HH24:MI:SS'

# Install PHP
RUN cd /tmp && \
    wget wget http://museum.php.net/php5/php-5.3.6.tar.gz && \
    tar xzf php-5.3.6.tar.gz
RUN cd /tmp/php-5.3.6 && \
    ./configure \
        --with-apxs2=/usr/local/apache2/bin/apxs \
        --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib/ \
        --enable-libxml \
        --enable-xml \
        --enable-mbstring \
        --enable-zip \
        --with-curl \
        --with-gd && \
    make && make install

# Install apc
RUN cd /tmp && \
    wget https://pecl.php.net/get/APC-3.1.9.tgz && \
    tar xzf APC-3.1.9.tgz
RUN cd /tmp/APC-3.1.9 && \
    phpize && \
    ./configure && make && make install

# Install redis
RUN cd /tmp && \
    wget https://pecl.php.net/get/redis-2.2.8.tgz && \
    tar xzf redis-2.2.8.tgz
RUN cd /tmp/redis-2.2.8 && \
    phpize && \
    ./configure && make && make install

COPY php.ini /usr/local/lib
COPY mime.types /etc/mime.types
COPY docker-entrypoint.sh /
RUN mkdir /usr/local/apache2/run
CMD /docker-entrypoint.sh

Oracleのせいで、行数が著しく増えています。

apachectlだと、Dockerが終了してしまうので、無理やりtailで永続的にしています。

app/docker-entrypoint.sh
#!/bin/bash

/usr/local/apache2/bin/apachectl start
tail -f /usr/local/apache2/logs/error_log

起動

docker-compose build
docker-compose up

2回目以降は、docker-compose upだけでOKです。

とにかくこれで、localhost:8000にアプリの画面が立ち上がることを確認しました。

8
11
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
8
11