Wordpress on Docker swarm plugin issues? - wordpress

I run a WP in docker container with mysql with docker-compose. I put a volume on host machine and everything goes well. During my development I install some themes.
When I am going to deploy my configuration to docker swarm:
1. I create from my wp container an image and commit it to repository
2. I share a volume from the host machine to wp service with mysql db
However when I run it in swarm mode - my installed themes are not there.
version: '3'
services:
db:
image: localhost:5000/db2
volumes:
- ./realsitermark_db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: localhost:5000/rw
volumes:
- ./engage/engage/:/var/www/html/wp-content/themes/engage
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress

You're mounting your theme engage using:
- ./engage/engage/:/var/www/html/wp-content/themes/engage.
To use uploads, mount the entire wp-content directory.

Related

Wordpress REST API not working - local instance, official docker image

I'm running a local Wordpress instance in a docker container build using wordpress latest image. According to Wordpress Site Health tool the REST API is not working. I get this error:
Error: cURL error 7: Failed to connect to localhost port 8000: Connection refused (http_request_failed)
My docker-compose looks like this
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
I tried also Bitnami image, but the effect is the same.
How can I get this working?
A friend solved this for me.
Stop the containers.
Change "8000:80" in docker-compose.yml to "80:80".
Remove db volume - this will remove all db data
docker volume ls find volume name
docker volume rm <name> in this case it's wordpress_db_data
Start the containers and go to http://localhost/
You could probably also just update the settings in the Wordpress dashboard but installing it again seemed more convenient.
Now Wordpress Site Health should show no errors.

How do I setup a local wordpress using Docker?

So I decided to try Docker for my local Wordpress development.
Luckily, Docker has a quickstart guide for that.
I followed the entire process and I *think* I understood most of it. However, when I had the Docker container up and running, it made a clean installation of Wordpress instead of using the local files I had for a project. I initially thought that changing the directory to the project folder allowed it to read the files in it. Apparently, I was mistaken. I've tried searching the net for an answer and
most of them are just tutorials into how to use Docker for WP.
So with that in mind, how do I create a Docker container (or change the Docker YAML file) that uses the local WP files I have?
docker-compose.yml
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Project structure
/project
/app
/sql
docker-compose.yml
I'm running on Ubuntu 19.04
Wordpress on docker
Create the docker-compose.yml with the follwing
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
volumes:
- ./app:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: DoKRteST
WORDPRESS_DB_HOST: mysql
mysql:
image: mysql:5.7
# Uncomment the below code to maintain the persistancy of the data
# volumes:
# - ./wordpress:/var/www/html
restart: always
environment:
MYSQL_ROOT_PASSWORD: DoKRteST
./app folder is the actual wordpress app folder
Simply click on
to run it on Play with docker
You just need to mount wp-content of the host to the container. you can look for wp-content in your current directory structure probably under app/wp-content
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
volumes:
- wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
You can read more details here and here

Install wordpress local site with Docker

I downloaded a github folder with a wordpress site, after the unzip the weight of it is about 1,8 gb.
Inside the master folder I've 9 folders, two of them named:
1: wp-content
2: wp-includes
I already created the docker-compose.yml file and the code inside it is this:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:5.1.1-php7.3-apache
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
db_data:
The lines up above are necessary only for install wordpress.
Now my question is, what could I do to install and launch the complete site that i downloaded ?
The entire process must be done with docker, install and launch the site.
Thank you for everything :)
Ensure you have the volume mount points which contains the existing app source code and the db files and the script to do db update.
wordpress section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com:/var/www/html
mysql section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com.20170808-024302.sql.gz:/docker-entrypoint-initdb.d/backup.sql.gz
- ./migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
This example uses nginx webserver
Ref : https://codeblog.dotsandbrackets.com/migrate-wordpress-docker/

Developing wordpress sites on Docker for Windows

It took me a while but I finally setup Wordpress in Docker for windows, the install went fine and I have a working wordpress site at http://localhost:8080 I can't for the life of me figure out how to access the wordpress files, such as everything in wp-content. I know they live in the container, but how do I go about developing with my code editor, I need to edit stuff in the themes folder.
I have seen in a tutorial that said to map my directories like this in my docker-compose.yml file
working_dir: /var/www/html
volumes:
- wordpress/wp-content/:/var/www/html/wp-content
I don't see how this helps be get to my files, I am running windows so I need to access them in my C drive ideally in C/Users/Andersk/Sites/Wordpress... I will include my current docker-compose.yml file below. Hopefully some one can help. Thanks
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data: {}
Click on the Docker icon in your system tray and select Settings, then click on Shared Drives. Make sure your C: drive is shared.
Now you should be able to add this to wordpress service section in your docker-compose.yml:
volumes:
- C:/Users/Andersk/Sites/Wordpress:/var/www/html/wp-content

Cannot host more than one Wordpress site with docker and nginx as reverse proxy

I am trying to host multiple sites on a single Digital Ocean VPS. I am using docker to achieve this. Each Wordpress site has its own database.
Using the docker-compose file of any of the two sites works fine and the site goes live. Adding a second does not work. (Navigating to the domain gives an nginx error of 'service temporarily unavailable')
I tried launching a static website from a container based on an apache image, and it does indeed work. So the nginx reverse proxy does successfully route traffic.
I am guessing that there is something more that I need to change between the two docker-compose files. Every tutorial or sample I've found stops after creating the first, and never actually shows a second Wordpress site being created.
Wordpress site 1:
docker-compose.yml
version: "3"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
container_name: site1_db
wordpress:
depends_on:
- db
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: www.site1.com
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: site1_wp
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
Wordpress site 2:
docker-compose.yml
version: "3"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
container_name: site2_db
wordpress:
depends_on:
- db
image: wordpress:latest
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: www.site2.com
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: site2_wp
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
A network named nginx-proxy was created beforehand to link all the containers. I left out the details about the nginx instance as it uses the well known jwilder image and like I said, it does seem to work just fine.
I finally found the answer. It is two-fold:
The WORDPRESS_DB_HOST environmental variable should not be the service, but rather the container that it is referencing
Thus change:
WORDPRESS_DB_HOST: db:3306
to:
WORDPRESS_DB_HOST: site1_db:3306
The same obviously goes for site2
The fix above still does not result in a working setup. When changing the database container to build from mariadb instead of mysql, it starts working! I have no idea in the slightest why this is true. Especially since the mysql instances can work on their own, but when running simultaneously, only mariadb works

Resources