Docker wordpress behind proxy generates 503 - wordpress

I tried to setup docker with multiple wordpress-sites behind a nginx-proxy. So I tried various instructions, but none worked.
This is one of them:
version: '3'
services:
nginx-web:
image: nginx
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
container_name: nginx-web
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx/conf.d:/etc/nginx/conf.d
- ./data/nginx/vhost.d:/etc/nginx/vhost.d
- ./data/nginx/html:/usr/share/nginx/html
- ./data/nginx/certs:/etc/nginx/certs:ro
- ./data/nginx/htpasswd:/etc/nginx/htpasswd:ro
depends_on:
- new-site-wordpress
nginx-gen:
image: jwilder/docker-gen
command: -notify-sighup nginx-web -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
container_name: nginx-gen
restart: always
volumes:
- ./data/nginx/conf.d:/etc/nginx/conf.d
- ./data/nginx/vhost.d:/etc/nginx/vhost.d
- ./data/nginx/html:/usr/share/nginx/html
- ./data/nginx/certs:/etc/nginx/certs:ro
- ./data/nginx/htpasswd:/etc/nginx/htpasswd:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./data/nginx.tmpl:/etc/docker-gen/templates:ro
nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-letsencrypt
restart: always
volumes:
- ./data/nginx/conf.d:/etc/nginx/conf.d
- ./data/nginx/vhost.d:/etc/nginx/vhost.d
- ./data/nginx/html:/usr/share/nginx/html
- ./data/nginx/certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
NGINX_DOCKER_GEN_CONTAINER: nginx-gen
NGINX_PROXY_CONTAINER: nginx-web
new-site-db:
container_name: demo-db
image: mariadb:latest
restart: unless-stopped
volumes:
- ./data/db/demo:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: demo_wordpress
MYSQL_USER: wordpress_user
MYSQL_PASSWORD: wordpress_password
new-site-wordpress:
depends_on:
- new-site-db
container_name: demo-wp
image: wordpress:latest
restart: unless-stopped
volumes:
- ./data/wp/demo:/var/www/html
- ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini
environment:
WORDPRESS_DB_HOST: demo-db:3306
WORDPRESS_DB_NAME: demo_wordpress
WORDPRESS_DB_USER: wordpress_user
WORDPRESS_DB_PASSWORD: wordpress_password
WORDPRESS_TABLE_PREFIX: wp_
VIRTUAL_HOST: demo.servles.de
LETSENCRYPT_HOST: demo.servles.de
LETSENCRYPT_EMAIL: louis#servles.de
wpcli:
image: tatemz/wp-cli
volumes:
- ./data/wp/demo:/var/www/html
depends_on:
- new-site-db
entrypoint: wp
networks:
default:
external:
name: test-network
All containers are created and work.
A wget to the IP of the demo-wp-container brings the correct index file.
But when the domain is called, only "503 Service Temporarily Unavailable
nginx/1.19.1"
What am I doing wrong? Or does someone have a working Compose-file?
Look forward to the support.

Related

installing wordpress with wp-cli from docker compose

I'm attempting to launch WordPress and set up WP-CLI with several options from docker, however, I am encountering difficulties in correctly configuring the Docker file.
the error:
The container name "/wordpress" is already in use by container "47a9242ec052b7a1196540ded8f1dce39ca97efb8e6def7cf5f9480221db991e". You have to remove (or rename) that container to be able to reuse that name.
My docker-compose file
services:
database:
image: ${DATABASE}:${DATABASE_VERSION}
platform: linux/x86_64
volumes:
- db_data:/var/lib/mysql
container_name: ${COMPOSE_PROJECT_NAME:-database}
restart: always
env_file: .env
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
networks:
- wordpress-network
phpmyadmin:
depends_on:
- database
image: phpmyadmin/phpmyadmin:latest
container_name: ${COMPOSE_PROJECT_NAME:-phpmyadmin}
restart: always
env_file: .env
environment:
PMA_HOST: ${PMA_HOST}
PMA_USER: ${PMA_USER}
PMA_PASSWORD: ${PMA_PASSWORD}
ports:
- ${PHPMYADMIN_PORT}
networks:
- wordpress-network
wordpress:
depends_on:
- database
image: wordpress:latest
container_name: ${COMPOSE_PROJECT_NAME:-wordpress}
restart: always
ports:
- ${PORTS}
env_file: .env
environment:
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
WORDPRESS_DEBUG: 1
volumes:
- wp_data:/var/www/html:rw
- ./configuration/apache2.conf:/etc/apache2/apache2.conf:ro
networks:
- wordpress-network
wp-cli:
depends_on:
- database
- wordpress
image: wordpress:cli
container_name: ${COMPOSE_PROJECT_NAME:-wordpress-cli}
env_file: .env
# This is required to run wp-cli with the same
# user-id as wordpress. This way there are no permission problems
# when running the cli
user: xfs
environment:
WP_CLI_CACHE_DIR: ${WP_CLI_CACHE_DIR}
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- wp_data:/var/www/html:rw
- ./bin/install-wp.sh:/usr/local/bin/install-wp:ro
networks:
- wordpress-network
volumes:
db_data:
wp_data:
networks:
wordpress-network:
driver: bridge

Implement docker compose file to deploy the following containers

I am new to docker-compose and I am trying to deploy a docker compose file to deploy the following containers:
-Wordpress
-MySQL
-A gateway: nginx in my case
I expect that all traffic to Wordpress to pass through the gateway, and no container other than the gateway to be accessible from the host. The gateway container will display ports 80 and 443. Can you help me set this up and config the ?
I did the followings:
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
networks:
- app-network
volumes:
wordpress:
dbdata:
networks:
app-network:
driver: bridge

ERROR: Named Volume "cerbot-etc:/etc/letsencrypt:rw' is used in service "webserver" but no declaration was found in the volumes section

I was following the digital ocean tutorial on how to install wordpress with docker-compose.
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose
I copied the docker-compose file the way it was written in the tutorial, double checked the indentation, checked to make sure the lines in question were written the exact way as the tutorial's example, and substituted the "example.com" with my own information.
Despite all of this I get this error.
ERROR: Named Volumne "cerbot-etc:/etc/letsencrypt:rw' is used in service "webserver" but no declaration was found in the volumes section.
My Docker-Compose file
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- app-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email terique#catricestudios.com --agree-tos --no-eff-email --staging -d cateyescollective.com -d www.cateyescollective.com
volumes:
certbot-etc:
wordpress:
dbdata:
networks:
app-network:
driver: bridge
The code from the tutorial
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- app-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email sammy#example.com --agree-tos --no-eff-email --staging -d example.com -d www.example.com
volumes:
certbot-etc:
wordpress:
dbdata:
networks:
app-network:
driver: bridge
Any help would be appreciated.
I had a similar problem following a similar tutorial, but I was able to solve it. In my case, I'm using certbotdata as the name of the volume instead of cert-bot that is yours.
My docker-compose.yml file is the following:
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
command: '--default-authentication-plugin=mysql_native_password'
env_file: .env
environment:
- MYSQL_DATABASE=$DB_NAME
ports:
- "$MYSQL_PORT:3306"
volumes:
- dbdata:/var/lib/mysql
networks:
- app-network
wordpress:
image: wordpress:5-fpm-alpine
depends_on:
- db
container_name: wordpress
restart: unless-stopped
volumes:
- wordpress:/var/www/html
- ./theme:/var/www/html/wp-content/themes/$THEME_NAME
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=$DB_NAME
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "$PORT:80"
- "$SSL_PORT:443"
volumes:
- wordpress:/var/www/html
- ./nginx/conf.d:/etc/nginx/conf.d
- certbotdata:/etc/letsencrypt
networks:
- app-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbotdata:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email youremail#email.com --agree-tos --no-eff-email --force-renewal -d localhost
volumes:
wordpress:
dbdata:
nginx:
certbotdata:
networks:
app-network:
driver: bridge
It looks pretty much the same but is working for me. Also you have to include the .env file to include the environmental variables.
My .env file:
MYSQL_ROOT_PASSWORD=root_password
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress_password
DB_NAME=wordpress
PORT=80
SSL_PORT=443
MYSQL_PORT=3306
THEME_NAME=mytheme
It's not necessary to mount the theme directory.
For more detailed instructions in how to setup the nginx.conf file you can follow the whole tutorial.
I hope that this works for you!

Docker container, connect to each others databases, Nginx proxy and WordPress

I trying to figure out how docker network and that kind of stuff works.
So here is my setup, I have 2 docker containers with WordPress and mysql. And theese two needs to be able to talk to each other thru direct database connections. And I have domain pointed to them also.
So I tried to set it up with an docker nginx proxy, but when i'm trying to visit that site thru the domain i'm getting 502 bat gateway.
So my docker ngxinx proxy compose file looks like this, but with different ports:
version: "3.1"
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: unless-stopped
networks:
default:
external:
name: nginx-proxy
And both of my WordPress containers look like this:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
VIRTUAL_HOST: wp1.local
VIRTUAL_PORT: 3000
volumes:
- ./wp:/var/www/html
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
expose:
- 3000
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
ports:
- "8086:3306"
mailhog:
image: mailhog/mailhog
ports:
- "1025:1025" # smtp server
- "8025:8025" # web ui
networks:
default:
external:
name: nginx-proxy
volumes:
db:
And I have added 127.0.0.1 wp1 to /etc/hosts
But when I start the proxy and one of the WP containers I'm getting bad gateway. And I have no clue how to move forward. And maybe this is not even the right way todo it. Becuase the problem i'm trying to solve is that wp2 needs to be able to connect to wp1 database thru custom pdo connection.
I tried to explain as good as I can, but this is a new area for me when it comes to docker networks. Also i'm running docker for windows with wsl2
You should add
networks:
- default
to each service definition in docker-compose.
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
VIRTUAL_HOST: wp1.local
VIRTUAL_PORT: 3000
volumes:
- ./wp:/var/www/html
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
expose:
- 3000
networks:
- default
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
ports:
- "8086:3306"
networks:
-default
mailhog:
image: mailhog/mailhog
ports:
- "1025:1025" # smtp server
- "8025:8025" # web ui
networks:
- default
networks:
default:
external:
name: nginx-proxy
volumes:
db:

Multi domains on same Docker container

I have a Magento 2 running on docker container and I would like to add a wordpress on the same container using one specific domain for each (blog.site and magento.site). I tried using nginx-proxy but it's not working my websites are not accessible anymore.
Here's my docker-compose.yml
version: "3"
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock
app:
image: markoshust/magento-nginx:1.13-8
links:
- db
- phpfpm
volumes: &appvolumes
- ~/.composer:/var/www/.composer:delegated
- appdata:/var/www/html
- sockdata:/sock
environment:
- "VIRTUAL_HOST=magento.site"
wordpress:
image: wordpress:latest
volumes:
- appwpdata:/var/www/html
environment:
- "VIRTUAL_HOST=blog.site"
phpfpm:
image: markoshust/magento-php:7.2-fpm-2
links:
- db
volumes: *appvolumes
db:
image: percona:5.7
ports:
- "3307:3307"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db
ports:
- '8080:80'
volumes:
- ./env/config.ini:/usr/local/etc/php/php.ini
volumes:
appdata:
appwpdata:
dbdata:
networks:
default:
external:
name: nginx-proxy

Resources