Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a docker image of php7-alpine

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to build a docker image of php7-alpine". In daily operation, I believe many people have doubts about how to build a docker image of php7-alpine. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to build a docker image of php7-alpine"! Next, please follow the editor to study!

Contains the following support

Php7

Mysql_pdo

Postgre_pdo

Phpredis

Swoole (optional, if the configuration of swoole,dockerfile and nginx will be changed)

Dockerfile is divided into two parts, one is php service, the other is nginx (optional under swoole)

Paste the code first.

# php7 #

FROM php:7.2-rc-fpm-alpine3.6ENV TIMEZONE Asia/ShanghaiENV PHP_MEMORY_LIMIT 512MENV MAX_UPLOAD 50MENV PHP_MAX_FILE_UPLOAD 200ENV PHP_MAX_POST 100M## swoole version If you need to install swoole, uncomment # ENV PHP_EXT_SWOOLE=swoole-2.0.6ENV PHP_REDIS=3.1.4# basic dependencies RUN sed-I & echo "${TIMEZONE}" > / etc "${TIMEZONE}" > / etc / timezone & &\ apk-update-repository= http://dl-4.alpinelinux.org/alpine/edge/testing add\ php7-common php7-intl php7-gd php7-mcrypt php7-openssl\ php7-gmp php7-json php7-dom php7-pdo php7-zip\ php7-zlib php7-mysqli php7-bcmath php7-pdo_mysql php7-pgsql\ php7-pdo_pgsql php7-gettext php7-xmlreaderhp7-xmlrpc\ php7-bz2 php7-iconv php7-curl php7-ctype php7- Fpm\ php7-mbstring php7-session php7-phar curl curl-dev postgresql-dev\ # if you use swoole, you need to cancel the comment # hiredis-dev libmcrypt-dev gmp-dev icu-dev linux-headers musl-- virtual. Phpize-deps $PHPIZE_DEPS\ tzdata & &\ php-r "copy ('https://getcomposer.org/installer', 'composer-setup.php') "& &\ php composer-setup.php & &\ php-r" unlink ('composer-setup.php'); "& &\ mv composer.phar / usr/local/bin/composer & &\ composer self-update & &\ sed-I-e" s / Daemonize\ s =\ s*yes/daemonize = no/g "/ etc/php7/php-fpm.conf & &\ sed-I-e" s/listen\ s =\ s*127.0.0.1:9000/listen = 9000G "/ etc/php7/php-fpm.d/www.conf & &\ sed-I" s | Date.timezone =. * | date.timezone = ${TIMEZONE} | "/ etc/php7/php.ini & &\ sed-I" s | memory_limit =. * | memory_limit = ${PHP_MEMORY_LIMIT} | "/ etc/php7/php.ini & &\ sed-I" s | upload_max_filesize = .* | upload_max_filesize = ${MAX_UPLOAD} | "/ etc/php7/php.ini & &\ sed-I" s | max_file_uploads =. * | max_file_uploads = ${PHP_MAX_FILE_UPLOAD} | "/ etc/php7/php.ini & &\ sed-I" s | post_max_size =. * | max_file_uploads = ${PHP_MAX_POST} | "/ etc/php7/php.ini & &\ sed-I" s / Cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/ "/ etc/php7/php.ini & &\ sed-I"sbank" extensionism phpcharts pgsql.dll.dllAccording to extensionism phpcharts pgsql.dll.dlls / "/ etc/php7/php.ini & &\ sed-I" s / Extension=php_pdo_pgsql.dll/extension=php_pdo_pgsql.dll/ "/ etc/php7/php.ini & &\ mkdir-p / usr/src/php/ext/redis & &\ curl-L https://github.com/phpredis/phpredis/archive/$PHP_REDIS.tar.gz | tar xvz-C / usr/src/php/ext/redis-- strip 1 & &\ echo 'redis' > > / usr/src/php-available-exts & &\ Docker-php-ext-install redis pgsql pdo pdo_mysql pdo_pgsql & &\ rm-rf / var/cache/apk/*# if you need to install swoole Cancel the following comment # RUN\ # cd / tmp\ # & & pecl download $PHP_EXT_SWOOLE\ # & & mkdir-p / tmp/$PHP_EXT_SWOOLE\ # & & tar-xf ${PHP_EXT_SWOOLE} .tgz-C / tmp/$PHP_EXT_SWOOLE-- strip-components=1\ # & & docker-php-ext-configure / tmp/$PHP_EXT_SWOOLE-- enable-async-redis-- enable-openssl-- enable-sockets= / usr/local/include/php/ext/sockets\ # & & docker-php-ext-install / tmp/$PHP_EXT_SWOOLE\ # & & rm-rf / tmp/$ {PHP_EXT_SWOOLE} * WORKDIR / www# put the code you need # COPY. / www# installation composer dependency # RUN composer install# php-fpm uses the following configuration EXPOSE 9000CMD ["php-fpm"] # swoole to launch swoole serverCMD ["php", "src/server", "start"] with the following configuration EXPOSE 950

# # swoole can be independent of nginx, so I post the nginx of php-fpm separately

Nginx-dockerfile:

From nginx:1.13.6-alpineENV TIME_ZONE Asiz/ShanghaiRUN sed-I's echo dlmut cdn.alpinelinux.orgUnigram mirrors.ustc.edu.cn no-cache tzdata / etc/apk/repositories & &\ apk update & &\ apk add-- no-cache tzdata & &\ echo "${TIME_ZONE}" > / etc/timezone & &\ ln-sf / usr/share/zoneinfo/$ {TIME_ZONE} / etc/localtime COPY default. Conf / etc/nginx/conf.dEXPOSE 80STOPSIGNAL SIGTERMCMD ["nginx" "- g", "daemon off "]

Nginx_php-fpm:default.conf:

Server {listen 80; server_name * .yourserver.com; location / {autoindex on; if ($request_filename! ~ * / (index\ .php | assets | uploads | phpinfo\ .php)) {rewrite ^ / (. *) $/ index.php/$1 last }} location ~ .php (/ | $) {fastcgi_ Split_path_info ^ (. +?\ .php) (/. *) $ Fastcgi_pass php-fpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / www$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params;}}

Compose:

* swoole's choreography template is easy to write, so I won't post it here.

Version: '2'services: php-fpm: image: "php-fpm" restart: always # Log system Do not write # logging: # driver: fluentd # options: # fluentd-address: "logaddr:24224" # tag: "docker/ {{.Name}} / {{.ID}} / {{.imageName}}" php-nginx: image: "php-nginx" depends_on: # these\ are escaped characters but do not know why they are displayed Remove\-php-fpm ports:\-"80:80" links:\-php-fpm restart: always # log system when using it, but do not write # logging: # driver: fluentd # options: # fluentd-address: "logaddr:24224" # tag: "docker/ {{.Name}} / {{.ID}} / {{.ImageName}}"

What I did was decouple php and nginx.

If there are multiple php services in the cluster that need to access each other

Because compose does not allow two services to link each other

So you need to create a network to access each other with the help of nginx in network

But at present, only v3 version of compose supports this function, and many old clusters can't support this function normally, so I won't post the code.

After editing, you can access index.php through port 80

At this point, the study on "how to build a docker image of php7-alpine" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report