avatar

Nginx PHP MySQL环境之Docker篇-入门版

未编辑版
------------------

更新操作系统

apt-get update && apt-get dist-upgrade -y

安装Docker

#使用Aliyun的镜像
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh - 
cd /home \
    && mkdir -p conf/nginx \
    conf/php \
    conf/mysql \
    data/htdocs \
    data/mysql \
    data/logs/nginx \
    dockerfiles/nginx \
    dockerfiles/php \
    dockerfiles/php/ext \
    dockerfiles/mysql

添加Docker国内镜像

echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=https://xxxx.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker

重启Docker

service docker restart

运行MySQL容器

docker run --name mysql -d \
    -p 3306:3306 \
    -v /home/data/mysql:/var/lib/mysql \
    -v /home/conf/mysql/conf.d:/etc/mysql/conf.d:ro \
    -v /home/conf/mysql/my.cnf:/etc/mysql/my.cnf:ro \
    -e MYSQL_ROOT_PASSWORD=123456 \
    -e MYSQL_USER=chobits \
    -e MYSQL_PASSWORD=123456 \
    mysql:5.7

常用命令

docker exec -it mysql /bin/bash

创建PHP容器

下载php-memcached插件

cd /home/dockerfiles/php/ext \
    && git clone https://github.com/php-memcached-dev/php-memcached.git /home/dockerfiles/php/ext/memcached \
    && cd memcached && git checkout php7

Dockerfile-alpine
--------------

FROM php:7.0-fpm-alpine

ADD ./ext/memcached /usr/src/php/ext/memcached

# 增加国内源, 请注意alpine的版本号
RUN echo -e 'http://mirrors.aliyun.com/alpine/alpine/v3.4/main/\nhttp://mirrors.aliyun.com/alpine/alpine/v3.4/community/' > /etc/apk/repositories

RUN apk update && apk add --no-cache --virtual .build-deps \
        libmemcached-dev \
        libmcrypt-dev \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev \
        libwebp-dev \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-webp-dir=/usr/include/ \
    && docker-php-ext-install -j1 gd \
    && docker-php-ext-install -j1 mcrypt \
    && docker-php-ext-install -j1 mysqli \
    && docker-php-ext-configure memcached --disable-memcached-sasl \
    && docker-php-ext-install -j1 memcached \
    && apk del .build-deps

RUN apk add --no-cache \
    libmemcached \
    libmcrypt \
    freetype \
    libjpeg-turbo \
    libpng \
    libwebp

Dockerfile-ubuntu
--------------

FROM php:7.0-fpm

ADD ./ext/memcached /usr/src/php/ext/memcached

RUN apt-get update && apt-get install -y --no-install-recommends \
        libmemcached-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng12-dev \
        libwebp-dev \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-webp-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install mysqli \
    && docker-php-ext-configure memcached \
    && docker-php-ext-install memcached \
    && rm -rf /var/lib/apt/lists/*

创建image

docker build -t ncj/php /home/dockerfiles/php

运行容器

docker run --name php -d \
    -v /home/data/htdocs:/home/htdocs \
    -v /home/conf/php/php-fpm.conf:/usr/local/etc/php-fpm.conf:ro \
    -v /home/conf/php/php-fpm.d:/usr/local/etc/php-fpm.d:ro \
    ncj/php

常用命令

docker exec -it php /bin/sh

重启php-fpm

kill -USR2 `cat /usr/local/var/run/php-fpm.pid`

运行nginx容器

docker run --name nginx -d \
    -p 80:80 \
    -p 443:443 \
    -v /home/conf/nginx/conf.d:/etc/nginx/conf.d:ro \
    -v /home/conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
    -v /home/data/certificate/live/key:/etc/nginx/certificate/key:ro \
    -v /home/data/certificate/live/csr:/etc/nginx/certificate/csr:ro \
    -v /home/data/certificate/live/cert:/etc/nginx/certificate/cert:ro \
    -v /home/data/htdocs:/home/htdocs \
    -v /home/data/logs/nginx:/var/log/nginx \
    --link php:php-fpm \
    nginx:1.10-alpine

常用命令

docker exec -it nginx /bin/sh
Comments ( 2 ) Trackbacks ( 0 ) Leave a Reply
  1. avatar
    (-_-#) 博主失踪多年了。。。貌似
  2. avatar
    沙发 ☆*:.。. o(≧▽≦)o .。.:*☆
  1. No trackbacks yet.

    目前尚无任何 trackbacks 和 pingbacks.

    トラックバックはまだありません。

  • ☆*:.。. o(≧▽≦)o .。.:*☆
  • _(:з」∠)_
  • ♪(´ε` )
  • ψ(`∇´)ψ
  • (-_-#)
  • (=´∀`)人(´∀`=)
  • \(//∇//)\
  • ♪(*^^)o∀*∀o(^^*)♪
  • (((o(*゚▽゚*)o)))
  • (´・_・`)
  • σ(^_^;)
  • ( *`ω´)
  • (ノ`Д´)ノ
  • (( _ _ ))..zzzZZ
  • ( ̄▽ ̄)
  • ヽ(`Д´#)ノ
  • ((((;゚Д゚)))))))
  • (>_<)
  • (T_T)
  • ( T_T)\(^-^ )
  • ε=ε=ε=ε=ε=ε=┌(; ̄◇ ̄)┘