Alpine based Laravel image.
- Build from official PHP docker image
- Installed some PHP extensions
- Installed XDebug extension but disable by default
- Add
artisan
bin alias tophp /var/www/artisan
- Auto create infinite loop when run
artisan schedule:run
with option--sleep
- Auto build and push by Github Workflow
- Tagging follow sermatic version
Image oanhnn/laravel
X.Y.Z
- the PATH version (git tagvX.Y.Z
)X.Y
- the MINOR versionX
- the MAJOR versionlatest
- the latest version
Image ghcr.io/oanhnn/laravel
edge
- the edge version, it is newest code from branchmaster
nightly
- the nightly version, it is builded daily at 8:20 AM UTC
NOTE: Using sematic version for production
Use like with official PHP image
All extensions are installed and enabled:
$ docker run --rm -it oanhnn/laravel:edge php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gmp
hash
iconv
imagick
intl
json
libxml
mbstring
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
Create a xdebug.ini
file like below and mount (or copy) to /usr/local/etc/php/conf.d/
directory in container
zend_extension=xdebug.so
[Xdebug]
xdebug.remote_enable=true
xdebug.remote_autostart=false
xdebug.remote_port=9000
xdebug.remote_connect_back=false
xdebug.remote_handler=dbgp
xdebug.idekey=CODE
Config your IDE to work with XDebug.
$ docker run --rm -it -v $(pwd):/var/www oanhnn/laravel artisan inspire
To run artisan schedule:run
in infinite loop, you MUST add option --sleep <seconds>
. With <seconds>
is loop sleep in seconds .
$ docker run --rm -d -v $(pwd):/var/www oanhnn/laravel artisan schedule:run --verbose --sleep 60
NOTE: This feature like command
artisan schedule:work
in Laravel 8+
You can copy all files in example
directory to your root directory of project and run docker-compose up -d
.
Default oanhnn/laravel
run:
-
PHP-FPM worker with
www-data
user (UID=82)$ docker run --rm -d --name php-fpm oanhnn/laravel:latest b634e56c859837d660ed8697b50e92d3f05efe89325e39c803b731c7f846864f $ docker exec php-fpm ps PID USER TIME COMMAND 1 root 0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf) 6 www-data 0:00 php-fpm: pool www 7 www-data 0:00 php-fpm: pool www 8 root 0:00 ps
-
All artisan command via
/usr/local/bin/artisan
withwww-data
(bysu-exec
)$ docker-compose exec horizon ps PID USER TIME COMMAND 1 root 0:00 {artisan} /bin/sh /usr/local/bin/artisan horizon 7 www-data 0:00 php /var/www/artisan horizon 14 www-data 0:00 /usr/local/bin/php artisan horizon:supervisor bb9e6284106d 25 www-data 0:00 /usr/local/bin/php artisan horizon:work redis --name=defau 38 root 0:00 ps
-
Other command with root user
However, you can also set run with other UID. See below example.
FROM oanhnn/laravel:latest
# Create new user with UID=1000 and GID=1000
RUN set -eux; \
addgroup -g 1000 dev; \
adduser -u 1000 -D -G dev dev
# Set PHP-FPM user
RUN set -eux; \
sed -i "s|^user =.*|user = dev|i" /usr/local/etc/php-fpm.d/www.conf; \
sed -i "s|^group =.*|user = dev|i" /usr/local/etc/php-fpm.d/www.conf; \
chown dev:dev /var/www
# Set artisan commands execute user
ENV EXEC_USER=dev
When mounting file or directory to container, you can have error about file permissions. To fix it, you can run:
$ sudo setfacl -dR -m u:82:rwX -m u:$(whoami):rwX ./
$ sudo setfacl -R -m u:82:rwX -m u:$(whoami):rwX ./
Or
$ sudo chmod -R g+w bootstrap/cache storage
$ sudo chown -R $(whoami):82 bootstrap/cache storage
All code contributions must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch, and send a pull request.
If you would like to help take a look at the list of issues.
If you discover any security related issues, please contact to me instead of using the issue tracker.
This project is available under the MIT license.
Copyright (c) 2021 Oanh Nguyen