Directory of docker:
docker -- config ---- nginx ---- php-fpm -- data -- images -- logs ---- nginx_log ---- php-fpm projects -- myweb.local
- Create a file myweb.local.conf in docker/config/nginx with code:
server { listen 80; listen [::]:80; root /var/www/html/myweb.local/public; index index.php index.html index.htm; client_max_body_size 100M; server_name myweb.local www.myweb.local; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri $uri/ /index.php?$query_string; fastcgi_pass myweb_php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { expires 1d; } location ~ /\. { log_not_found off; deny all; } } - Create a file custom.ini in docker/config/php-fpm with code:
post_max_size = 1024M upload_max_filesize = 1024M error_log = /var/log/php-fpm.log display_errors = on opcache.enable=0 memory_limit=1024M zend.assertions=-1 enable_dl=1 error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT - Create a file composer.Dockerfile in docker/images with code:
FROM composer:latest - Create a file mysql.Dockerfile in docker/images with code:
FROM mysql:8.0.31 - Create a file nginx.Dockerfile in docker/images with code:
FROM nginx:latest - Create a file php.Dockerfile in docker/images with code:
FROM bitnami/php-fpm:8.1.11 RUN apt-get update RUN apt-get install -y vim - Create a file .env in docker directory
COMPOSE_PROJECT_NAME=myweb - Create a file docker-compose.yml in docker directory
version: "3" services: myweb_nginx: dns: - 8.8.8.8 - 4.4.4.4 build: context: ./images dockerfile: nginx.Dockerfile working_dir: /var/www/html container_name: myweb_nginx ports: - "8181:80" volumes: - ../projects:/var/www/html - ./logs/nginx_log:/var/log/nginx - ./config/nginx/myweb.local.conf:/etc/nginx/conf.d/myweb.local.conf links: - myweb_php - myweb_mysql myweb_php: build: context: ./images dockerfile: php.Dockerfile container_name: myweb_php restart: always volumes: - ../projects:/var/www/html - ./logs/php-fpm/php-fpm.log:/var/log/php-fpm.log - ./config/php-fpm/custom.ini:/opt/bitnami/php/etc/conf.d/custom.ini myweb_mysql: build: context: ./images dockerfile: mysql.Dockerfile container_name: myweb_mysql restart: always ports: - "3310:3306" volumes: - ./data/mysql:/var/lib/mysql command: [ --default-authentication-plugin=mysql_native_password, --skip-host-cache ] environment: #MYSQL_ALLOW_EMPTY_PASSWORD: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: myweb MYSQL_USER: admin MYSQL_PASSWORD: password myweb_composer: build: context: ./images dockerfile: composer.Dockerfile container_name: myweb_composer links: - myweb_php - Start build docker with command:
Note: make sure cd to the docker directory on the terminal
Step 1:
After docker build is successful and next step 2docker-compose buildStep 2:
docker-compose up -d
First, please add the domain to the hosts file of windows or hosts on macos:
Windows : C:\Windows\System32\drivers\etc\hosts
Macos: /etc/hosts
127.0.0.1 myweb.local
::1 myweb.localprojects -- myweb.local=> Clone the source code from git
Open terminal and run with code :
- Composer update
docker exec myweb_php bash -c "cd /var/www/html/myweb.local && composer update" - Copy .env file from .env.example
docker exec myweb_php bash -c "cp /var/www/html/myweb.local/.env.example /var/www/html/myweb.local/.env" - Run artisan migrate
docker exec myweb_php bash -c "cd /var/www/html/myweb.local && php artisan migrate" - Run npm install for format code with re-commit
Note: make sure cd to the myweb.local directory on the terminal
projects -- myweb.local
And runnpm i