Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Last active July 31, 2018 10:33
Show Gist options
  • Save rutcreate/dd7bc524f9439d221d60c51435396f81 to your computer and use it in GitHub Desktop.
Save rutcreate/dd7bc524f9439d221d60c51435396f81 to your computer and use it in GitHub Desktop.
Docker WordPress with NGINX
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
}
location ~ /\.ht {
deny all;
}
}
version: '3.4'
services:
nginx:
image: nginx:1.15-alpine
volumes:
- ./html:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- 8888:80
wordpress:
image: wordpress:4-php7.2-fpm
volumes:
- ./html:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: example
elasticsearch:
image: elasticsearch:5.3-alpine
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es_data:/usr/share/elasticsearch/data
deploy:
resources:
limits:
memory: 1g
reservations:
memory: 1000m
volumes:
db_data:
es_data:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$http_x_real_ip - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
@rutcreate
Copy link
Author

rutcreate commented Jul 31, 2018

Setup

  1. cd <your-project-directory>
  2. Copy docker-compose.yml to your project directory.
  3. Create directory
    $ mkdir html nginx at the same level of docker-compose.yml
  4. Copy default.conf and nginx.conf to <your-project-directory>/nginx/

Your project structure should be look like this:

<your-project-directory>
-- docker-compose.yml
-- html
-- nginx
---- default.conf
---- nginx.conf

Run Docker

  1. Make sure your machine has already install Docker
  2. For Docker Compose run command: $ docker-compose up -d (for daemon mode) or docker-compose up.
  3. For Docker Swarm run command: $ docker stack deploy -c docker-compose.yml <project-name>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment