此容器包含 PHP 7.3 和Nginx1.18环境,用户可以自己使用Makefile 一键编译安装PHP环境,也可以直接使用制作好的镜像运行项目
git clone https://github.com/CiaraLi/dockerFiles.git
进入php7.3 可看到如下结构
├── Dockerfile //构建容器的DockerFIle
└── src
├── nginx //nginx配置文件
│ ├── default.conf
│ ├── nginx.conf
│ └── start.sh //nginx启动命令
├── nginx-1.18.0.tar.gz //Nginx 源码安装包
├── php //PHP配置文件
│ ├── php-fpm.conf
│ ├── php.ini
│ └── www.conf
├── php-7.3.5.tar.gz //PHP 源码安装包
├── php_install.sh //安装脚本
├── phpredis-4.0.2.tar.gz //PHPREDIS 安装包
└── www-data //PHP脚本目录
└── index.php
#!/bin/bash
homeDir="/tmp"
php="php-7.3.5"
phpDir="/usr/local/php"
nginx="nginx-1.18.0"
nginxDir="/usr/local/nginx"
phpredis="phpredis-4.0.2"
#!/bin/bash
php-fpm
nginx -g "daemon off;"
进入php7.3目录
FROM centos:7
USER root
LABEL MAINTAINER="<ciara@gmail.com>"
COPY src/ /tmp/
## isntall nginx by source code
WORKDIR /tmp
ENV TZ=Asia/Shanghai
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;\
echo "--HELLO PHP7.3--" > /etc/motd ; \
echo "set encoding=utf-8" > ~/.vimrc; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone ;\
chmod +x php_install.sh && ./php_install.sh
EXPOSE 80 443
VOLUME ["/home/www-data","/usr/local/nginx/conf/include"]
CMD ["/bin/sh","/start.sh" ]
cd php7.3
docker build -t php7 ./
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
TALdeMacBook-Pro1:php7.3 tal$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php7 latest b25b01f69449 6 minutes ago 556MB
├── config //项目Nginx配置
│ └── host.conf
└── www-data // 项目根目录
└── hello.php
## API ##
server {
listen 80;
root /home/www-data/;
index index.php;
server_name 127.0.0.1 localhost;
charset utf-8;
access_log /home/www_logs/test_access.log combined;
error_log /home/www_logs/test_error.log error;
location / {
try_files $uri $uri/ /index.php?$args;
}
client_max_body_size 50m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
fastcgi_index index.php;
include fastcgi_params;
}
}
docker run -itd -v /Users/php/config:/usr/local/nginx/conf/include -v /Users/php/www-data/:/home/www-data/ -p 80:80 --name php7 php7
235525a5bc962aa6e5b36cba093c7e59b3213445bdd9e182ee5d1bce5c26d4dc
TALdeMacBook-Pro1:php7.3 tal$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
235525a5bc96 php7 "/bin/sh /start.sh '…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp php7
docker tag php7 iongdoc/php7.3:v1.0
TALdeMacBook-Pro1:php7.3 tal$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
iongdoc/php7.3 v1.0 b25b01f69449 57 minutes ago 556MB
php7 latest b25b01f69449 57 minutes ago 556MB
TALdeMacBook-Pro1:php7.3 tal$ docker push iongdoc/php7.3:v1.0
Using default tag: latest
The push refers to repository [docker.io/iongdoc/php7]
c6e1c6b2fcc9: Pushed
5f70bf18a086: Mounted from iongdoc/php7.3:v1.0
d8d88d72c7ab: Pushed
174f56854903: Mounted from iongdoc/php7.3:v1.0
latest: digest: sha256:657cf8fd994fd809ac5901d44c4d9a8c119fd7c436f5d68a4859c0a67c604fc7 size: 1157
TALdeMacBook-Pro1:php7.3 tal$ docker pull iongdoc/php7.3:v1.0
v1.0: Pulling from iongdoc/php7.3
Digest: sha256:63f9b5b7127d4f88a700897b8cb7ffcb8645796d7d66757dd7b905c6f1a3aa2b
Status: Image is up to date for iongdoc/php7.3:v1.0
docker.io/iongdoc/php7.3:v1.0