Skip to content

Commit 95d190d

Browse files
author
Dale Nguyen
committed
Initiated Docker for Drupal 8 Development
0 parents  commit 95d190d

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed

.env

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
PROJECT_NAME=drupal8
2+
3+
DRUPAL_VERSION=8.6.12
4+
5+
NGINX_TAG=alpine
6+
NGINX_PORT=8080:80
7+
8+
DRUPAL_TAG=8.6-fpm-alpine
9+
10+
MYSQL_TAG=8
11+
12+
DB_NAME=drupal
13+
DB_USER=drupal
14+
DB_PASSWORD=drupal
15+
DB_ROOT_PASSWORD=password

.gitigore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Drupal folders
2+
drupal/mysql
3+
drupal/web
4+
drupal/backup.sql

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: "3"
2+
3+
services:
4+
web:
5+
image: nginx:$NGINX_TAG
6+
container_name: "${PROJECT_NAME}_nginx"
7+
ports:
8+
- $NGINX_PORT
9+
volumes:
10+
- "./drupal/web:/var/www/html"
11+
- "./drupal/nginx.conf:/etc/nginx/conf.d/default.conf"
12+
depends_on:
13+
- php
14+
php:
15+
image: drupal:$DRUPAL_TAG
16+
container_name: "${PROJECT_NAME}_drupal"
17+
volumes:
18+
- "./drupal/web:/var/www/html"
19+
restart: always
20+
depends_on:
21+
- mysql
22+
mysql:
23+
image: mysql:$MYSQL_TAG
24+
container_name: "${PROJECT_NAME}_mysql"
25+
entrypoint: ['/entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
26+
environment:
27+
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
28+
MYSQL_USER: $DB_USER
29+
MYSQL_PASSWORD: $DB_PASSWORD
30+
MYSQL_DATABASE: $DB_NAME
31+
volumes:
32+
- "./drupal/mysql:/var/lib/mysql"
33+
restart: always
34+
# drush:
35+
# image: drush/drush:8-alpine
36+
# volumes:
37+
# - "./drupal/web:/var/www/html"
38+
# - "./drupal/export:/export"

drupal-install.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /bin/bash
2+
3+
[[ -f .env ]] && source .env
4+
5+
if [ $DRUPAL_VERSION ]
6+
then
7+
echo "Start with Drupal version ${DRUPAL_VERSION}"
8+
else
9+
echo "Drupal version is not defined. Set the default version to 8.6.12"
10+
DRUPAL_VERSION='8.6.12'
11+
fi
12+
13+
mkdir drupal/web
14+
curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz
15+
mv drupal.tar.gz drupal/web
16+
cd drupal/web
17+
tar -zx --strip-components=1 -f drupal.tar.gz
18+
rm drupal.tar.gz

drupal/nginx.conf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
#charset koi8-r;
6+
#access_log /var/log/nginx/log/host.access.log main;
7+
8+
root /var/www/html;
9+
10+
#error_page 404 /404.html;
11+
12+
# redirect server error pages to the static page /50x.html
13+
#
14+
error_page 500 502 503 504 /50x.html;
15+
location = /50x.html {
16+
root /usr/share/nginx/html;
17+
}
18+
19+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
20+
#
21+
#location ~ \.php$ {
22+
# proxy_pass http://127.0.0.1;
23+
#}
24+
25+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
26+
#
27+
# location ~ \.php$ {
28+
# #root html;
29+
# fastcgi_pass php:9000;
30+
# fastcgi_index index.php;
31+
# fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
32+
# include fastcgi_params;
33+
# }
34+
35+
## serve imagecache files directly or redirect to drupal if they do not exist.
36+
location ~* files/styles {
37+
access_log off;
38+
expires 30d;
39+
try_files $uri @drupal;
40+
}
41+
42+
## serve imagecache files directly or redirect to drupal if they do not exist.
43+
location ~* ^.+.(xsl|xml)$ {
44+
access_log off;
45+
expires 1d;
46+
try_files $uri @drupal;
47+
}
48+
49+
## Default location
50+
location / {
51+
try_files $uri $uri/ @drupal;
52+
index index.php;
53+
}
54+
55+
location @drupal {
56+
rewrite ^/(.*)$ /index.php?q=$1 last;
57+
}
58+
59+
## Images and static content is treated different
60+
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
61+
access_log off;
62+
expires 30d;
63+
}
64+
65+
## Parse all .php file in the /var/www directory
66+
location ~ .php$ {
67+
include fastcgi_params;
68+
fastcgi_split_path_info ^(.+\.php)(.*)$;
69+
fastcgi_pass backend;
70+
fastcgi_index index.php;
71+
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
72+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
73+
fastcgi_param QUERY_STRING $query_string;
74+
fastcgi_param REQUEST_METHOD $request_method;
75+
fastcgi_param CONTENT_TYPE $content_type;
76+
fastcgi_param CONTENT_LENGTH $content_length;
77+
fastcgi_intercept_errors on;
78+
fastcgi_ignore_client_abort off;
79+
fastcgi_connect_timeout 60;
80+
fastcgi_send_timeout 180;
81+
fastcgi_read_timeout 180;
82+
fastcgi_buffer_size 128k;
83+
fastcgi_buffers 4 256k;
84+
fastcgi_busy_buffers_size 256k;
85+
fastcgi_temp_file_write_size 256k;
86+
}
87+
88+
## Disable viewing .htaccess & .htpassword
89+
location ~ /\.ht {
90+
deny all;
91+
}
92+
}
93+
94+
upstream backend {
95+
server php:9000;
96+
}

readme.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Drupal 8 - Docker Local Development
2+
3+
Docker enviroment setting up for Drupal 8 local development
4+
5+
Drupal version: 8.6.12
6+
7+
## Clone this project
8+
9+
```sh
10+
git clone https://github.com/dalenguyen/drupal8-docker.git
11+
cd drupal8-docker
12+
```
13+
14+
## Before bringing up containers
15+
16+
This command will install Drupal 8.6.12 to drupal/web folder. For Windows user, you can skip this step. Instead, you have download drupal 8 from the main website and put in under drupal/web folder.
17+
18+
```sh
19+
sh drupal-install.sh
20+
```
21+
22+
## Getting started
23+
24+
Manage the containers
25+
26+
```sh
27+
docker-compose up -d
28+
docker-compose down
29+
```
30+
31+
## Database management
32+
33+
Export database
34+
35+
```sh
36+
docker exec drupal8_mysql /usr/bin/mysqldump -u root --password=password drupal > drupal/backup.sql
37+
```
38+
39+
Import database
40+
41+
```sh
42+
cat drupal/backup.sql | docker exec -i drupal8_mysql /usr/bin/mysql -u root --password=password drupal
43+
```
44+
45+
## Notes
46+
47+
Remember to change the host name of MySQL is to __drupal8_mysql__ when you install Drupal.
48+
49+
## Reference
50+
51+
[Docker for WordPress Development](https://github.com/dalenguyen/wordpress-docker)

0 commit comments

Comments
 (0)