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
Related
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!
I created a setup for a wordpress installation with docker-compose:
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
volumes:
- dbdata-dev:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- rn-dev-network
wordpress:
depends_on:
- db
image: wordpress:5.5.3-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=$MYSQL_DATABASE
volumes:
- ./wordpress/wp-content:/var/www/html/wp-content
- ./wordpress/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- wordpress-dev:/var/www/html
networks:
- rn-dev-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress-dev:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
networks:
- rn-dev-network
volumes:
wordpress-dev:
dbdata-dev:
networks:
rn-dev-network:
driver: bridge
Via FTP, I moved a theme into the wp-content/themes folder. The theme shows up on wordpress when starting the container, but it does not show any preview picture and is missing all pictures/assets when loading it.
I don't see what is missing. When I ssh into the container and check the folder, the volume is correctly linked and the wordpress theme is showing up in the correct folder.
Preview Screen of Wordpress Theme Setup
You need to mount the image file to the nginx container, because static content is served via the nginx container.
The Php container only executes the php.
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress-dev:/var/www/html
- ./wordpress/wp-content:/var/www/html/wp-content
- ./nginx-conf:/etc/nginx/conf.d
networks:
- rn-dev-network
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.
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
I have a setup based on docker-letsencrypt-nginx-proxy-companion running a django container and a wordpress container on the same Docker Host. I have added to domains to each of the container, so the wordpress container is reachable with mydomain.com and www.mydomain.com and the django container with subdomain.mydomain.com. This is configured in the VIRTUAL_HOST env and its working perfectly so far. I get all certificates and I can connect to each of them.
The main Issue I have now is, that the wordpress container needs to curl the django container and vice versa. But if I go into the django or wordpress container and try to make a call to e.g. subdomain.mydomain.com I get the following error:
$ curl mydomain.com
Hostname was NOT found in DNS cache
and then he tries to connect to the IP and is ending up in a timeout. If I make a curl from local or a different server I get a 200 without any problems on each of those. I read sth about a DNS resolve issue but atm I couldn't find a solution. Do you have a clue what I could do in this case?
Thanks in advance!
My Containers:
Nginx Proxy Compose
version: "2"
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- "/var/www/certificates:/etc/nginx/certs:ro"
- "/etc/nginx/vhost.d"
- "/usr/share/nginx/html"
- "/var/run/docker.sock:/tmp/docker.sock:ro"
letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
restart: always
volumes_from:
- nginx-proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/var/www/certificates:/etc/nginx/certs:rw"
networks:
default:
external:
name: proxy-network
Wordpress Compose
version: '2'
services:
mariadb:
build:
context: .
dockerfile: build/env/mysql/Dockerfile
env_file: .env
restart: "always"
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- prod-database:/var/lib/mysql
php:
build:
context: .
dockerfile: build/env/php-fpm/Dockerfile
env_file: .env
restart: "always"
volumes:
- ${SRC_APP_PERSISTENT}:/var/www/html
links:
- mariadb:mysql
web:
build:
context: .
dockerfile: build/env/nginx/Dockerfile
restart: "always"
links:
- php:fpm
volumes_from:
- php
environment:
- VIRTUAL_HOST=mydomain.com,www.mydomain.com
- VIRTUAL_PORT=443
- VIRTUAL_NETWORK=proxy-network
- LETSENCRYPT_HOST=mydomain.com,www.mydomain.com
- LETSENCRYPT_EMAIL=info#mydomain.com
ports:
- "80"
volumes:
prod-database:
driver: local
networks:
default:
external:
name: proxy-network
Django Compose
version: '2'
volumes:
postgres_data_dev: {}
postgres_backup_dev: {}
services:
postgres:
build: ./compose/postgres
volumes:
- postgres_data_dev:/var/lib/postgresql/data
- postgres_backup_dev:/backups
environment:
- POSTGRES_USER=dbuser
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
env_file: .env
command: /start-dev.sh
depends_on:
- postgres
environment:
- POSTGRES_USER=dbuser
- USE_DOCKER=yes
- VIRTUAL_HOST=subdomain.mydomain.com
- VIRTUAL_PORT=443
- VIRTUAL_NETWORK=proxy-network
- LETSENCRYPT_HOST=subdomain.mydomain.com
- LETSENCRYPT_EMAIL=info#mydomain.com
volumes:
- .:/app
ports:
- "8000"
links:
- postgres
- mailhog
pycharm:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
depends_on:
- postgres
environment:
- POSTGRES_USER=dbuser
volumes:
- .:/app
links:
- postgres
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
networks:
default:
external:
name: proxy-network