LoginSignup
5
11

More than 5 years have passed since last update.

docker-composeでApache+PHP+MariaDBの環境構築

Last updated at Posted at 2017-07-18

やりたいこと

docker-composeを試しつつ、3系の書式(主にLongSyntaxでの記述)で書いてみたかったのでメモ

事前準備

Docker-Engineが1.13以降でないと3.3では動かない為、更新を行う

https://docs.docker.com/cs-engine/1.13/
の手順に従ってリポジトリを追加し、インストール

curl -fsSL 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | sudo apt-key add -
$ sudo add-apt-repository \
   "deb https://packages.docker.com/1.13/apt/repo/ \
   ubuntu-$(lsb_release -cs) \
   main"
$ sudo apt-get update
$ sudo apt-get -y install docker-engine

ymlを記述

docker-compose.yml
version: "3.3"
services:
    php:
        build:
            context: ./php
            dockerfile: Dockerfile
        depends_on:
            - db
        volumes:
            - type: bind
              source: /var/vm/html
              target: /var/www/html
        ports:
            - target: 80
              published: 80
              protocol: tcp
              mode: host
    db:
        image: mariadb:10 #10.x latest
        volumes:
            - type: bind
              source: /var/vm/db
              target: /var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: ROOTPW
            MYSQL_USER: test
            MYSQL_PASSWORD: TESTPW
            MYSQL_DATABASE: testdb
        ports:
            - target: 3306
              published: 3306
              protocol: tcp
              mode: host
./php/Dockerfile
FROM php:7.1-apache
RUN apt-get update && apt-get install -y \
       apt-utils \
       zlib1g-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN docker-php-source extract \
    && docker-php-ext-install pdo pdo_mysql \
    && docker-php-ext-install zip \
    && docker-php-ext-install opcache
RUN pecl install apcu
RUN echo "extension=apcu.so" > /usr/local/etc/php/conf.d/apcu.ini

雑感

単体で起動するよりもシンプルに記述が出来て素晴らしい…
ymlファイルの記述は3.2以降で冗長的に記述できるようになったようで
ドキュメント込みで残す場合には有りなのかな?

修正

phpのオフィシャルコンテナではmysqlが有効でなかった為、コンテナのbuildを追加

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