Resolves network issue with non-unique service names not playing well with the external letsencrypt network.
This commit is contained in:
parent
db9e08f943
commit
b3c3c387f6
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
.env
|
.env
|
||||||
|
docker-compose.yml
|
||||||
|
default.conf
|
18
README.md
18
README.md
@ -56,15 +56,19 @@ HTML_VOLUME=test_html_staging
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
### Initialize project with unique COMPOSE_PROJECT_NAME
|
||||||
|
|
||||||
|
[./generate-compose-nginx.sh](generate-compose-nginx.sh)
|
||||||
|
|
||||||
### Upgrade Process
|
### Upgrade Process
|
||||||
|
|
||||||
1. Stop the current containers and remove volumes:
|
1. Stop the current containers and remove volumes:
|
||||||
```bash
|
```bash
|
||||||
docker compose down -v
|
docker compose down -v
|
||||||
|
|
||||||
# Optional Steps
|
# Optional Steps for testing and development
|
||||||
|
|
||||||
# Clean volumes
|
# Remove external database and content volume (DANGER: only do this if you have backed up these two volumes)
|
||||||
grep -E 'DB_VOLUME|CONTENT_VOLUME' .env | cut -d '=' -f2 | xargs -I {} sh -c 'docker volume rm {} 2>/dev/null; docker volume create {}'
|
grep -E 'DB_VOLUME|CONTENT_VOLUME' .env | cut -d '=' -f2 | xargs -I {} sh -c 'docker volume rm {} 2>/dev/null; docker volume create {}'
|
||||||
|
|
||||||
# Remove Wordpress Image
|
# Remove Wordpress Image
|
||||||
@ -76,22 +80,22 @@ docker rmi $(grep IMAGE_WEB .env | cut -d '=' -f2)
|
|||||||
- Modify version in `Dockerfile.wordpress_fpm`
|
- Modify version in `Dockerfile.wordpress_fpm`
|
||||||
- Update `IMAGE_WEB` in `.env` file
|
- Update `IMAGE_WEB` in `.env` file
|
||||||
|
|
||||||
3. Build and test the new environment:
|
3. Build and reinstall the new environment:
|
||||||
```bash
|
```bash
|
||||||
# Build initial configuration
|
# Build custom Wordpress image
|
||||||
docker compose -f docker-compose.first.yml build
|
docker compose -f docker-compose.first.yml build
|
||||||
|
|
||||||
# Test the build
|
# Install or Upgrade Wordpress /var/www/html volume (not external) from custom Wordpress image
|
||||||
docker compose -f docker-compose.first.yml up -d
|
docker compose -f docker-compose.first.yml up -d
|
||||||
|
|
||||||
# Stop test environment
|
# Stop and remove Wordpress container, but keep html volume
|
||||||
docker compose -f docker-compose.first.yml down
|
docker compose -f docker-compose.first.yml down
|
||||||
|
|
||||||
# Start production environment
|
# Start production environment
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Migrate content:
|
4. Migrate content (e.g., themes, plugins) after a new installation or upgrade:
|
||||||
```bash
|
```bash
|
||||||
# In the wordpress service, copy new content to production
|
# In the wordpress service, copy new content to production
|
||||||
cp -a wp-content-new/* wp-content/
|
cp -a wp-content-new/* wp-content/
|
||||||
|
@ -5,7 +5,7 @@ server {
|
|||||||
|
|
||||||
listen 80;
|
listen 80;
|
||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
server_name wordpress;
|
server_name wordpress_${COMPOSE_PROJECT_NAME};
|
||||||
root /var/www/html;
|
root /var/www/html;
|
||||||
index index.php;
|
index index.php;
|
||||||
|
|
||||||
@ -24,11 +24,11 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# pass the PHP scripts to FastCGI server listening on wordpress2:9000
|
# pass the PHP scripts to FastCGI server listening on wordpress:9000
|
||||||
#
|
#
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
fastcgi_pass wordpress:9000;
|
fastcgi_pass wordpress_${COMPOSE_PROJECT_NAME}:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
@ -11,7 +11,7 @@ services:
|
|||||||
WORDPRESS_VERSION: ${WORDPRESS_VERSION}
|
WORDPRESS_VERSION: ${WORDPRESS_VERSION}
|
||||||
image: ${IMAGE_WEB:-web}
|
image: ${IMAGE_WEB:-web}
|
||||||
volumes:
|
volumes:
|
||||||
- html:/var/www/html
|
- html:/var/www/html
|
||||||
environment:
|
environment:
|
||||||
- WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST:-database:3306}
|
- WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST:-database:3306}
|
||||||
- WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-fake}
|
- WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-fake}
|
||||||
@ -26,8 +26,9 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
|
- custom_network
|
||||||
- letsencrypt
|
- letsencrypt
|
||||||
- default
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
html:
|
html:
|
||||||
@ -35,4 +36,6 @@ volumes:
|
|||||||
|
|
||||||
networks:
|
networks:
|
||||||
letsencrypt:
|
letsencrypt:
|
||||||
external: true
|
external: true
|
||||||
|
custom_network:
|
||||||
|
name: ${COMPOSE_PROJECT_NAME}_network # Uses project-specific name
|
@ -18,8 +18,9 @@
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
database:
|
database_${SERVICE_SUFFIX}:
|
||||||
image: ${IMAGE_DATABASE:-database}
|
image: ${IMAGE_DATABASE:-database}
|
||||||
|
container_name: ${COMPOSE_PROJECT_NAME}_database
|
||||||
volumes:
|
volumes:
|
||||||
- db:/var/lib/mysql
|
- db:/var/lib/mysql
|
||||||
environment:
|
environment:
|
||||||
@ -34,13 +35,14 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- letsencrypt
|
- custom_network
|
||||||
|
|
||||||
wordpress:
|
wordpress_${SERVICE_SUFFIX}:
|
||||||
# build:
|
# build:
|
||||||
# context: .
|
# context: .
|
||||||
# dockerfile: Dockerfile.wordpress_fpm
|
# dockerfile: Dockerfile.wordpress_fpm
|
||||||
image: ${IMAGE_WEB:-wordpress}
|
image: ${IMAGE_WEB:-wordpress}
|
||||||
|
container_name: ${COMPOSE_PROJECT_NAME}_wordpress
|
||||||
volumes:
|
volumes:
|
||||||
- html:/var/www/html
|
- html:/var/www/html
|
||||||
- content:/var/www/html/wp-content
|
- content:/var/www/html/wp-content
|
||||||
@ -61,19 +63,21 @@ services:
|
|||||||
command: >
|
command: >
|
||||||
bash -c "chown -R www-data:www-data /var/www/html/wp-content && php-fpm"
|
bash -c "chown -R www-data:www-data /var/www/html/wp-content && php-fpm"
|
||||||
networks:
|
networks:
|
||||||
|
- custom_network
|
||||||
- letsencrypt
|
- letsencrypt
|
||||||
- default
|
|
||||||
|
|
||||||
# nginx:latest and/or can be customized
|
# nginx:latest and/or can be customized
|
||||||
web:
|
web_${SERVICE_SUFFIX}:
|
||||||
# build:
|
# build:
|
||||||
# context: .
|
# context: .
|
||||||
# dockerfile: Dockerfile.nginx
|
# dockerfile: Dockerfile.nginx
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
|
container_name: ${COMPOSE_PROJECT_NAME}_web
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- html:/var/www/html/
|
- html:/var/www/html/
|
||||||
- content:/var/www/html/wp-content
|
- content:/var/www/html/wp-content
|
||||||
|
- ./wp-config.php:/var/www/html/wp-config.php
|
||||||
- ./default.conf:/etc/nginx/conf.d/default.conf
|
- ./default.conf:/etc/nginx/conf.d/default.conf
|
||||||
- ./nginx.conf:/etc/nginx/nginx.conf
|
- ./nginx.conf:/etc/nginx/nginx.conf
|
||||||
environment:
|
environment:
|
||||||
@ -82,8 +86,8 @@ services:
|
|||||||
- LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL:-me}
|
- LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL:-me}
|
||||||
- LETSENCRYPT_TEST=${LETSENCRYPT_TEST:-true}
|
- LETSENCRYPT_TEST=${LETSENCRYPT_TEST:-true}
|
||||||
networks:
|
networks:
|
||||||
- letsencrypt
|
- custom_network
|
||||||
- default
|
- letsencrypt
|
||||||
|
|
||||||
# No variable substition for volumes in this version
|
# No variable substition for volumes in this version
|
||||||
volumes:
|
volumes:
|
||||||
@ -99,5 +103,5 @@ volumes:
|
|||||||
networks:
|
networks:
|
||||||
letsencrypt:
|
letsencrypt:
|
||||||
external: true
|
external: true
|
||||||
# default:
|
custom_network:
|
||||||
# name: ${COMPOSE_PROJECT_NAME}_default
|
name: ${COMPOSE_PROJECT_NAME}_network # Uses project-specific name
|
19
generate-compose-nginx.sh
Executable file
19
generate-compose-nginx.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Docker service names are designed to be static, not dynamic,
|
||||||
|
# primarily due to the need for predictable and consistent communication
|
||||||
|
# between services within a Docker Compose environment. However, since an
|
||||||
|
# external letsencrypt network is utilized, conflicts occur if the service
|
||||||
|
# name is not unique to the project. This script resolves that issue by
|
||||||
|
# generating a docker-compose.yml file with unique service names, which is
|
||||||
|
# the COMPOSE_PROJECT_NAME
|
||||||
|
|
||||||
|
# Load variables from .env file
|
||||||
|
if [ -f .env ]; then
|
||||||
|
source .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
export SERVICE_SUFFIX=${COMPOSE_PROJECT_NAME:-main}
|
||||||
|
export COMPOSE_PROJECT_NAME
|
||||||
|
envsubst < docker-compose.template.yml > docker-compose.yml
|
||||||
|
envsubst '${COMPOSE_PROJECT_NAME}' < default.template.conf > default.conf
|
Loading…
x
Reference in New Issue
Block a user