1.安装一个docker的技术预览版
2.
docker pull nginx docker pull mariadb docker pull php:7.0-fpm
查看镜像
3.新建docker配置目录
4. 启动php
#710 为php的image id 前三位 docker run -d -p 9000:9000 -v /Users/kn/nmp/www/:/var/www/html/ --name myphp 710
查看php的ip
docker inspect --format='{{.NetworkSettings.IPAddress}}' myphp
172.17.0.2
5 配置nginx
nginx目录下新建nginx.conf
server { listen 80 default_server; server_name _; root /usr/share/nginx/html; location / { index index.html index.htm index.php; autoindex off; } location ~ \.php(.*)$ { root /var/www/html/; fastcgi_pass 172.17.0.2:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
启动nginx
docker run -d -p 80:80 -v /Users/kn/nmp/nginx/conf.d:/etc/nginx/conf.d \ -v /Users/kn/nmp/www:/usr/share/nginx/html --name mynginx 1e8
查看运行中的容器
写入测试文件
6.docker常用命令
1、停止所有正在运行的容器
docker kill $(docker ps -a -q)
2、删除所有已停止运行的容器
docker rm $(docker ps -a -q)
3、查看容器运行状态
docker status
4、进入容器内进行命令行操作
docker exec -it content-name-or-id /bin/bash
7.php安装需要的拓展
#进入到php容器中 docker exec -it myphp /bin/bash #查看已加载拓展 php -m docker-php-ext-install mysqli docker-php-ext-install pdo_mysql docker-php-ext-install mbstring docker-php-ext-install sockets #安装Redis拓展 pecl install igbinary docker-php-ext-enable igbinary pecl install redis-4.0.1 docker-php-ext-enable redis
以下是可以使用docker-php-ext-install 安装的拓展
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
其他的需要手动安装
bz2 扩展的安装, 读写 bzip2(.bz2)压缩文件 $ apt-get update && \ apt-get install -y --no-install-recommends libbz2-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) bz2 enchant 扩展的安装, 拼写检查库 $ apt-get update && \ apt-get install -y --no-install-recommends libenchant-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) enchant gd 扩展的安装. 图像处理 $ apt-get update && \ apt-get install -y --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ docker-php-ext-install -j$(nproc) gd gmp 扩展的安装, GMP$ apt-get update && \ apt-get install -y --no-install-recommends libgmp-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) gmp soap wddx xmlrpc tidy xsl 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libxml2-dev libtidy-dev libxslt1-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) soap wddx xmlrpc tidy xsl zip 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libzip-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) zip snmp 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libsnmp-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) snmp pgsql, pdo_pgsql 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libpq-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) pgsql pdo_pgsql pspell 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libpspell-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) pspell recode 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends librecode-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) recode pdo_firebird 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends firebird-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) pdo_firebird pdo_dblib 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends freetds-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-configure pdo_dblib --with-libdir=lib/x86_64-linux-gnu && \ docker-php-ext-install -j$(nproc) pdo_dblib ldap 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libldap2-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && \ docker-php-ext-install -j$(nproc) ldap imap 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libc-client-dev libkrb5-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \ docker-php-ext-install -j$(nproc) imap interbase 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends firebird-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) interbase intl 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libicu-dev && \ rm -r /var/lib/apt/lists/* && \ docker-php-ext-install -j$(nproc) intl mcrypt 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends libmcrypt-dev && \ rm -r /var/lib/apt/lists/* && \ pecl install mcrypt-1.0.1 && \ docker-php-ext-enable mcrypt imagick 扩展的安装 $ export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" && \ apt-get update && \ apt-get install -y --no-install-recommends libmagickwand-dev && \ rm -rf /var/lib/apt/lists/* && \ pecl install imagick-3.4.3 && \ docker-php-ext-enable imagick memcached 扩展的安装 $ apt-get update && \ apt-get install -y --no-install-recommends zlib1g-dev libmemcached-dev && \ rm -r /var/lib/apt/lists/* && \ pecl install memcached && \ docker-php-ext-enable memcached redis 扩展的安装 $ pecl install redis-4.0.1 && docker-php-ext-enable redis opcache 扩展的安装 $ docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
安装完拓展,退出容器 ,重启服务
exit docker restart myphp
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com