1 Star 1 Fork 0

Holyhi/Docker Container - PHP Laravel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

The docker environment for PHP Laravel.

This image was built based on the DockerHub official image. It included the required extensions for Laravel. and included some common extensions.

Table Of Contents

Usage

apache:

This image was built based-on php/apache image. Add support to Laravel's scheduled tasks, queue, and specify the execution user with $UID and $GID. The container will create the run user at startup.

The Apache service, scheduled tasks (by artisan schedule:run), queue work processes (by artisan queue:work), and any commands by artisan will run as a user with $UID and $GID.

# for docker
▶ docker run -d \
--restart always \
--hostname simple \
--name simple
-p 80:80 \
-e UID=$(id -u) \
-e GID=$(id -g) \
-e SCHEDULE=On \
-e SUPERVISORD=On \
-v /path/to/your/php.ini:/usr/local/etc/php/php.ini \
-v /path/to/host:/var/www/html \
troytse/php-laravel:apache

# for podman
▶ podman run -d \
--restart always \
--hostname simple \
--name simple
-p 80:80 \
-e UID=$(id -u) \
-e GID=$(id -g) \
--uidmap 0:0:999 --gidmap 0:0:999 \
--uidmap 1000:$(id -u):1 --gidmap 1000:$(id -g):1 \
-e SCHEDULE=On \
-e SUPERVISORD=On \
-v /path/to/your/php.ini:/usr/local/etc/php/php.ini \
-v /path/to/host:/var/www/html \
quay.io/troytse/php-laravel:apache

A typical example for apache:

▶ docker exec -it sample ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.8  0.2 223304 32828 ?        Ss   10:27   0:00 apache2 -DFOREGROUND
root        47  0.0  0.0   5512  2060 ?        Ss   10:27   0:00 /usr/sbin/cron
contain+    58  0.0  0.0 223336 10068 ?        S    10:27   0:00 apache2 -DFOREGROUND
contain+    59  0.0  0.0 223336 10068 ?        S    10:27   0:00 apache2 -DFOREGROUND
contain+    60  0.0  0.0 223336 10068 ?        S    10:27   0:00 apache2 -DFOREGROUND
contain+    61  0.0  0.0 223336 10068 ?        S    10:27   0:00 apache2 -DFOREGROUND
contain+    62  0.0  0.0 223336 10068 ?        S    10:27   0:00 apache2 -DFOREGROUND
root        65  0.0  0.1  26204 16452 ?        Ss   10:27   0:00 /usr/bin/python2 /usr/bin/supervisord -c /var/local/etc/supervisord.conf
contain+    66  1.0  0.2 107956 46652 ?        S    10:27   0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
contain+    67  0.9  0.2 107956 46636 ?        S    10:27   0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
contain+    68  1.0  0.2 107956 46968 ?        S    10:27   0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
contain+    70  0.9  0.2 107956 46636 ?        S    10:27   0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=low
contain+    71  0.9  0.2 107956 46636 ?        S    10:27   0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=low
root        99  0.0  0.0   7640  2732 pts/0    R+   10:27   0:00 ps -aux

fpm-alpine:

This image was built based-on php/fpm-alpine image. Add support to Laravel's scheduled tasks, queue, and specify the execution user with $UID and $GID. The container will create the run user at startup.

The PHP-FPM processes, scheduled tasks (by artisan schedule:run), queue work processes (by artisan queue:work), and any commands by artisan will run as a user with $UID and $GID.

# for docker
▶ docker run -d \
--restart always \
--hostname sample \
--name sample \
-p 9000:9000 \
-e UID=$(id -u) \
-e GID=$(id -g) \
-e SCHEDULE=On \
-e SUPERVISORD=On \
-v /path/to/your/php.ini:/usr/local/etc/php/php.ini \
-v /path/to/host:/var/www/html \
troytse/php-laravel:fpm-alpine

# for podman
▶ podman run -d \
--restart always \
--hostname sample \
--name sample \
-p 9000:9000 \
-e UID=$(id -u) \
-e GID=$(id -g) \
--uidmap 0:0:999 --gidmap 0:0:999 \
--uidmap 1000:$(id -u):1 --gidmap 1000:$(id -g):1 \
-e SCHEDULE=On \
-e SUPERVISORD=On \
-v /path/to/your/php.ini:/usr/local/etc/php/php.ini \
-v /path/to/host:/var/www/html \
quay.io/troytse/php-laravel:fpm-alpine

A typical example for fpm-alpine:

▶ docker exec -it sample ps -a
sample:/var/www/html# ps -A
PID   USER     TIME  COMMAND
    1 root      0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
   25 root      0:00 /usr/local/bin/supercronic /usr/local/etc/crontab.txt
   36 containe  0:00 php-fpm: pool www
   37 containe  0:00 php-fpm: pool www
   38 root      0:00 {supervisord} /usr/bin/python3 /usr/bin/supervisord -c /usr/local/etc/supervisord.conf
   39 containe  0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
   40 containe  0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
   41 containe  0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
   42 containe  0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=low
   43 containe  0:00 /usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=low
   92 root      0:00 ps -A

Environment Variables

UID / GID

(Default: 0)

  • These two variables specify to run as the user for the Apache/PHP-FPM, scheduled task, queue work, and artisan command.
  • (for apache, $UID and $GID will override the $APACHE_RUN_USER and $APACHE_RUN_GROUP)

SCHEDULE

(On/Off, Default: Off)

  • This variable specifies whether to add the "php artisan schedule:run" into the crontab after the container is created.

SUPERVISORD

(On/Off, Default: Off)

  • This variable specifies whether to run the supervisor service after the container is created.

Supervisor configuration

(Optional)

  • Put your customized "supervisord.conf" file in the project folder.
    • Example:
    [program:queue-work-default]
    process_name=%(program_name)s_%(process_num)02d
    directory=/var/www/html
    command=/usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=default,high
    autostart=true
    autorestart=true
    user=%(ENV_RUN_USER)s
    numprocs=3
    redirect_stderr=true
    
    [program:queue-work-low]
    process_name=%(program_name)s_%(process_num)02d
    directory=/var/www/html
    command=/usr/local/bin/php /var/www/html/artisan queue:work --daemon --queue=low
    autostart=true
    autorestart=true
    user=%(ENV_RUN_USER)s
    numprocs=2
    redirect_stderr=true
    

Other Environment Variables

For other environment variables, please reference to the base image

Console Commands

  • Run artisan command in the container.

    ▶ docker/podman exec -it <container_name> artisan <command>
    
  • Run composer command in the container.

    ▶ docker/podman exec -it <container_name> composer <command>
    
  • You can create a shell script in your project directory to quickly call them.

    • For example, create a shell named "container_exec" and content as follows:
    • docker:
    #!/bin/sh
    sudo docker exec -it your_container_name $@ 
    
    • podman:
    #!/bin/sh
    podman exec -it your_container_name $@ 
    
    • Then you can call them like this:
    ▶ ./container_exec artisan make:job DoSomething
    ▶ ./container_exec composer dump-autoload
    
    • (The above operations will be run as the specified user by $UID and $GID.)

Included Extensions

[PHP Modules]
bcmath
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
imap
intl
json
ldap
libxml
mbstring
memcached
msgpack
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
swoole
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
MIT License Copyright (c) 2019 Troy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

The docker environment for PHP Laravel. This image was built based on the DockerHub official image. It included the required extensions for Laravel. and included some common extensions. 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者 (1)

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Docker
1
https://gitee.com/holyhi/docker-php-laravel.git
git@gitee.com:holyhi/docker-php-laravel.git
holyhi
docker-php-laravel
Docker Container - PHP Laravel
master

搜索帮助