PHP&MySQL范例精解_创建、修改、重用-docker环境搭
2020-04-06 本文已影响0人
程序猿阿乐
PHP.and.MySQL.Create.Modify.Reuse
PHP&MySQL范例精解_创建、修改、重用-docker环境搭建-3.准备php-gd
准备php
拉取php镜像,因为书本是针对php5的,我们就不拉取7的了
docker pull php:5.6-fpm
选择这个php:5.6-fpm
,而不是php:5.6-fpm-alpine3.8
是想安装gd更方便点
创建临时容器
docker run -d --rm --name tmp-php-fpm php:5.6-fpm
进入容器
localhost:~ jjkkll$ bash -c "clear && docker exec -it tmp-php-fpm sh"
可以找到相应的目录,上次找到目录位置用的php:7.2.12-fpm-alpine3.8的镜像,发现这个位置是一样的.
/var/www/html
/usr/local/etc/
将配置放到容器外
若要将配置放到容器外,可以在容器外,拷贝容器里的配置
docker cp tmp-php-fpm:/usr/local/etc/ /Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-etc/
可以在相应目录下看到配置已经拷贝到外面了
localhost:~ jjkkll$ tree -N /Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-etc/
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-etc/
└── etc
├── pear.conf
├── php
│ ├── conf.d
│ ├── php.ini-development
│ └── php.ini-production
├── php-fpm.conf
├── php-fpm.conf.default
└── php-fpm.d
├── docker.conf
├── www.conf
└── zz-docker.conf
启动时docker run
命令里加上-v
参数指定即可:
-v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-etc/etc/:/usr/local/etc/
制作包含gd的镜像
准备sources.list
国内更新包的速度太慢,改成163的镜像:
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-gd/sources.list,文件内容:
deb http://mirrors.163.com/debian/ stretch main non-free contrib
deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
Dockerfile
准备Dockerfile文件
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-gd/Dockerfile,文件内容:
FROM php:5.6-fpm
COPY Dockerfile /
COPY sources.list /
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && mv /sources.list /etc/apt/
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
进入目录,创建镜像
docker build -t php-5.6-fpm-gd ./Dockerfile-php-5.6-fpm-gd