自己制作镜像,并通过docker-compose部署
制作镜像目录结构
[root@harbor larvel-crm-dockfile]# tree ..├── conf│ ├── nginx.conf│ ├── nginx-site.conf│ └── supervisord.conf├── docker-compose1.yml├── docker-compose.yml├── Dockerfile└── start.sh
nginx.conf
#user nobody;worker_processes auto;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;client_header_buffer_size 4k;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 2;client_max_body_size 25m;server_tokens off;#gzip on;include /etc/nginx/conf.d/*.conf;}
nginx-site.conf
server {listen 80;server_name _;root /var/www/html/laravel-crm/public;index index.php index.html index.htm;error_log /var/log/nginx/error_laravel.log error;access_log /var/log/nginx/access_laravel.log;location / {try_files $uri $uri/ /index.php?$args;}location ~ \.php$ {try_files $uri =404;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass unix:/var/run/php-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_index index.php;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;include fastcgi_params;}location ~ .*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$ {expires 2d;}location ~ .*\.(?:js|css)$ {expires 8h;}location ~ /\. {log_not_found off;deny all;}}
supervisord.conf
[unix_http_server]file=/dev/shm/supervisor.sock ; (the path to the socket file)[supervisord]logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)logfile_backups=10 ; (num of main logfile rotation backups;default 10)loglevel=info ; (log level;default info; others: debug,warn,trace)pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)nodaemon=false ; (start in foreground if true;default false)minfds=1024 ; (min. avail startup file descriptors;default 1024)minprocs=200 ; (min. avail process descriptors;default 200)user=root ;; the below section must remain in the config file for RPC; (supervisorctl/web interface) to work, additional interfaces may be; added by defining them in separate rpcinterface: sections[rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL for a unix socket[program:php-fpm]command = /usr/local/sbin/php-fpm --force-stderr --nodaemonize --fpm-config /usr/local/etc/php-fpm.d/www.confautostart=trueautorestart=truepriority=5stdout_events_enabled=truestderr_events_enabled=truestdout_logfile=/dev/stdoutstdout_logfile_maxbytes=0stderr_logfile=/dev/stderrstderr_logfile_maxbytes=0stopsignal=QUIT[program:nginx]command=/usr/sbin/nginx -g "daemon off; error_log /dev/stderr info;"autostart=trueautorestart=truepriority=10stdout_events_enabled=truestderr_events_enabled=truestdout_logfile=/dev/stdoutstdout_logfile_maxbytes=0stderr_logfile=/dev/stderrstderr_logfile_maxbytes=0stopsignal=QUIT[include]files = /etc/supervisor/conf.d/*.conf
start.sh
#!/bin/bash# Set custom webrootif [ ! -z "$WEBROOT" ]; thensed -i "s#root /var/www/html;#root ${WEBROOT};#g" /etc/nginx/conf.d/default.confelsewebroot=/var/www/htmlfi# Display errors in docker logsif [ ! -z "$PHP_ERRORS_STDERR" ]; thenecho "log_errors = On" >> /usr/local/etc/php/conf.d/docker-vars.iniecho "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/docker-vars.inifiif [ ! -z "$PUID" ]; thenif [ -z "$PGID" ]; thenPGID=${PUID}fideluser nginxaddgroup -g ${PGID} nginxadduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx -u ${PUID} nginxelseif [ -z "$SKIP_CHOWN" ]; thenchown -Rf nginx.nginx /var/www/htmlfifi# Start supervisord and servicesexec /usr/bin/supervisord -n -c /etc/supervisord.conf
Dockerfile
FROM richarvey/nginx-php-fpm:latestRUN apk add --no-cache lua-resty-core nginx-mod-http-lua \&& apk add nodejsRUN rm -Rf /etc/nginx/nginx.confCOPY conf/nginx.conf /etc/nginx/nginx.confCOPY conf/nginx-site.conf /etc/nginx/conf.d/default.confCOPY conf/supervisord.conf /etc/supervisord.confCOPY start.sh /start.shRUN cd /var/www/html \&& composer create-project krayin/laravel-crm \&& chown -Rf nginx.nginx /var/www/html \&& chmod +x /start.shEXPOSE 80WORKDIR /var/www/htmlCMD ["/start.sh"]
docker-compose.yml
version: '3'services:web:image: "larvel-crm:v2"container_name: "laravel_crm"restart: alwaysports:- "1800:80"depends_on:- mysqllinks:- mysqlvolumes:- "/etc/localtime:/etc/localtime"mysql:image: mysql:5.7container_name: mysqlrestart: alwaysenvironment:MYSQL_DATABASE: 'laravel-crm'MYSQL_USER: 'laravel-crm'MYSQL_PASSWORD: 'laravel-crm.123'MYSQL_ROOT_PASSWORD: 'marketin.123'MYSQL_ROOT_HOST: '%'volumes:- "/home/web/mysql/data/:/var/lib/mysql"- "/etc/localtime:/etc/localtime"
启动
docker-compose up -d
.env 文件配置
[root@harbor larvel-crm-dockfile]# docker exec -it 9692d09d3a48 bashbash-5.0# lsindex.php laravel-crm storagebash-5.0# cat laravel-crm/.envAPP_NAME='Krayin CRM'APP_ENV=localAPP_VERSION=1.2.2APP_KEY=base64:rZqVFiNwGsEm4ohnoeVYzFTH9uHLJ7b3glvJQNf7w30=APP_DEBUG=trueAPP_URL=http://10.4.7.22APP_TIMEZONE=Asia/KolkataLOG_CHANNEL=stackLOG_LEVEL=debugDB_CONNECTION=mysqlDB_HOST=mysqlDB_PORT=3306DB_DATABASE=laravel-crmDB_USERNAME=rootDB_PASSWORD=marketin.123BROADCAST_DRIVER=logCACHE_DRIVER=fileQUEUE_CONNECTION=syncSESSION_DRIVER=fileSESSION_LIFETIME=120MEMCACHED_HOST=127.0.0.1REDIS_HOST=127.0.0.1REDIS_PASSWORD=nullREDIS_PORT=6379MAIL_MAILER=smtpMAIL_HOST=mailhogMAIL_PORT=1025MAIL_USERNAME=nullMAIL_PASSWORD=nullMAIL_ENCRYPTION=nullMAIL_FROM_ADDRESS=laravel@krayincrm.comMAIL_FROM_NAME="${APP_NAME}"AWS_ACCESS_KEY_ID=AWS_SECRET_ACCESS_KEY=AWS_DEFAULT_REGION=us-east-1AWS_BUCKET=PUSHER_APP_ID=PUSHER_APP_KEY=PUSHER_APP_SECRET=PUSHER_APP_CLUSTER=mt1MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
db 初始化
[root@harbor larvel-crm-dockfile]# docker exec -it 9692d09d3a48 bashcd /var/www/html/laravel-crm && php artisan krayin-crm:install
登录信息
Email: admin@example.comPassword: admin123
