URL issue in Docker Wordpress site - wordpress

I wanted to create a local dev environment for a wordpress site using docker.
So I have the following docker-compose file :
version: '3'
services:
db:
image: mariadb
restart: on-failure
environment:
- MYSQL_DATABASE=${WP_DB_NAME}
- MYSQL_USER=${WP_DB_USER}
- MYSQL_PASSWORD=${WP_DB_USER_PASSWORD}
volumes:
#- ./db_data:/var/lib/mysql
- ./mysql_dump/backup.sql:/docker-entrypoint-initdb.d/backup.sql
- ./mysql_dump/migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
networks:
- local
wordpress:
image: wordpress
depends_on:
- db
restart: always
ports:
- 8080:80
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=${WP_DB_USER}
- WORDPRESS_DB_PASSWORD=${WP_DB_USER_PASSWORD}
- WORDPRESS_DB_NAME=${WP_DB_NAME}
volumes:
- ./htdocs:/var/www/html
networks:
local:
ipv4_address: 172.23.0.4
networks:
local:
driver: bridge
ipam:
config:
- subnet: 172.23.0.0/24
I use volume to start mariadb with existing database dump.
Website is loading fine, but some URLs are wrong :
When I try to connect, I am redirected to :
http://172.23.0.4/172.23.0.4/wp-admin/ for example
Some js scripts are also not loaded due to wrong URLs like
http://172.23.0.4172.23.0.4/wp-includes/js/tinymce/tinymce.min.js?ver=4920-20181217
I checked the general settings in the admin panel, and the values siteurl and home in the database and they are correct : 172.23.0.4.
The website in production (no docker but classic LAMP install) is working fine by the way…
Do you have any hints ? (I'm not that familiar with web development, especially with wordpress)

Looks like specifying 172.23.0.4 in wordpress settings for home and siteurl is somehow (don't know why though) causing the issue.
Instead, setting the value to http://172.23.0.4 fixed the problem.
If someone has some explanation, please tell me.

Related

Wordpress on Docker (Synology NAS) with different networks

first, sorry for my bad english, hope you can understand me.
i have the following task.
I want to run a (maybe more) wordpress installation on my synology nas. Therefore, i installed Docker and run portainer for creating some stuff.
My main idea is to create the following:
Create different container with separated wordpress installations
Create mysql container for hosting the different wordpress databases, each for every wordpress app
for the wordpress container there is a own network called "app_network" (bridge, attachable)
for the mysql container there is another network called "db_backend" (bridge, attachable)
So far, so god. At the moment i created one WP container, the mysql container and the two networks. Everything seems to be fine.
wordpress container is created with docker-compose (stack in portainer)
mysql container is created with docker-compose (stack in portainer)
I created a db for wordpress in the mysql container manually - local login on container works perfect.
the mysql container is in the network db_backend
the woordpress container is in the network app_network and additionally connected to the db_backend network (assigend ip´s looks correct)
But...if i am calling the wordpress page i got "Error establishing a database connection"
My yaml looks like this:
#mysql.yaml
version: '3.9'
services:
db:
image: mysql:latest
restart: on-failure:3
volumes:
- /volume1/docker/databases:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mysuperstrongpassword
container_name: db_mysql
networks:
- db_backend
networks:
db_backend:
driver: bridge
external: true
#worppess.yaml
version: '3.9'
services:
#frontend
wp_app:
image: wordpress:latest
restart: on-failure:3
ports:
- '49200:80'
- '49201:443'
volumes:
- /volume1/docker/wp_app/wp_t:/var/www/html
environment:
WORDPRESS_DB_HOST: db_mysql:3306 //wrong entry? tried hostname, ip, service
WORDPRESS_DB_NAME: mydb
WORDPRESS_DB_USER: myuser
WORDPRESS_DB_PASSWORD: mypassword
networks:
- db_backend
- app_network
networks:
#172.168.29.1/24
db_backend:
driver: bridge
external: true
#172.168.30.1/24
app_network:
driver: bridge
external: true
After all i was able to read about docker, docker-networking and docker compose i thought my solution should work, all can be deployed without any errors, except the database connection error :( ...
Is the way of connection the container between the networks correct?
May i edit the wp-config.php with the information and add them to the wordpress containe?
Can anyone help?
Replace this WORDPRESS_DB_HOST: db_mysql:3306 with WORDPRESS_DB_HOST: db

How to backup dockerized wordpress on linode?

I deployed wordpress to linode using docker-compose for my friend and everythings have worked well for 3 months. But now my friend want to stop linode and i need to backup everything back to local machine.
My wp site is just a simple blog. I deployed 3 services by docker-compose which are wordpress, mysql, php_myadmin. Here is my docker-compose.yaml file:
version: "3.0"
services:
mysqlwp:
container_name: mysqlwp
image: mysql:5
environment:
- MYSQL_ROOT_PASSWORD=${PASSWORD}
- MYSQL_DATABASE=${DATABASE}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${PASSWORD}
restart: always
#Mount database
volumes:
- '${MYSQL_DATA_DIR}:/var/lib/mysql'
wordpress:
container_name: wordpress
image: wordpress:latest
environment:
- WORDPRESS_DB_NAME=${DATABASE}
- WORDPRESS_DB_USER=${DB_USER}
- WORDPRESS_DB_PASSWORD=${PASSWORD}
ports:
- '80:80'
links:
- 'mysqlwp:mysql'
depends_on:
- 'mysqlwp'
#Mount source code
volumes:
- '${SOURCE_CODE_DIR}:/var/www/html'
restart: always
phpMyAdmin:
container_name: phpMyAdmin
image: phpmyadmin/phpmyadmin
links:
- 'mysqlwp:mysql'
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysqlwp
depends_on:
- 'mysqlwp'
ports:
- '8888:80'
restart: always
I am not an expert in wordpress and docker, im just learning them forward. I found a ton of plugins of wordpress that help me backup but i am not familiar with them and not sure that what should i pick ?
Should i just backup all the images and database ? How should organize them well for the next relaunch ?
Since you map ${SOURCE_CODE_DIR} to /var/www/html and ${MYSQL_DATA_DIR} to /var/lib/mysql, you should create a backup of the ${SOURCE_CODE_DIR} and ${MYSQL_DATA_DIR} which are stored on the host machine.
It's the whole of your data, other data are temporary and related to the images and docker. If you're looking for creating some backup of the images, you should look for the following topics:
docker save ... command.
docker load ... command.
Related sources:
docker save
docker load
Docker import/export vs. load/save

How should I set up a development environment with Docker for WordPress themes?

Little disclaimer before I start: I am a Docker newbie.
My question is mostly stated as above, with a little bit more to my requirements:
I want to have a "full" development experience. That is, I want to be able to use VS Code, WebStorm, etc. to do development with full-featured guesser and code intelligence. This is what my current setup is lacking.
I want to have a docker-compose.yml that I can commit into my source repository and not worry about "how it will run" on multiple platforms. I think what I have below accomplishes that, but I am very open to criticism.
docker-compose.yml:
version: '3.1'
services:
wp:
image: wordpress
restart: always
ports:
- 48080:80
links:
- db:mysql
volumes:
- themes:/var/www/html/wp-content/themes
environment:
WORDPRESS_DB_PASSWORD: example
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
themes:
Any tips for moving forward?
The theme volume did not work on my machine. If I run docker-compose up I get the following error:
This worked for me on Ubuntu 18.04:
version: '3.1'
services:
wp:
image: wordpress
restart: always
ports:
- 48080:80
links:
- db:mysql
volumes:
- ./themes:/var/www/html/wp-content/themes
environment:
WORDPRESS_DB_PASSWORD: example
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
Everything else looks quite good, only improvement for now would be hosting your WordPress on your local file system:
That would give you the possibility to debug WordPress easily and you have full control over the stack.
Downside: User permission can be a problem with Docker. Normally every process inside the container will be executed as root. If WordPress writes a file it has root permissions even on you local file system.

Plugin not working in Wordpress installed via Docker

I am beginner in docker and have setup wordpress in Docker. Everything was working fine except some plugin not working well as they should be. In my understanding, docker needs some volume mounted to work but i can't find any location of where they might be. For eg. it says "Wordpress copying /var/ww/html but there is actually nothing. The main problem was when i wanted to convert wordpress into Static site but the plugin simply static cant't generate the files in localhost.
I am running docker Server Version: 17.09.0-ce in Ubuntu 17.04 and
here is my docker-compose configuration.
docker-compose.yml
wordpress:
image: wordpress
links:
- wordpress_db:mysql
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
ports:
- 8080:80
wordpress_db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: examplepass
phpmyadmin:
image: corbinu/docker-phpmyadmin
links:
- wordpress_db:mysql
ports:
- 8181:80
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: examplepass
Install php-zip and the plugin will actually start to work.

Drupal and Docker with local sync folder

I'm trying to setup a drupal 8 installation with docker / docker-compose for local development. What I'd like to have is a local folder that is synchronized with the drupal container's /var/www/html directory, so I could work locally. What is the best way to achieve that?
This is my docker-compose.yml:
mysql:
image: mysql:5.5
ports:
- "3306:3306"
environment:
- MYSQL_USER=xxxxx
- MYSQL_PASSWORD=xxxxxx
- MYSQL_ROOT_PASSWORD=xxxxxxx
- MYSQL_DATABASE=xxxxxxx
drupal:
image: drupal:8.0.4
links:
- mysql
ports:
- "8080:80"
You have to map a folder to your dockerhost. Using docker-compose you would have to add "volumes" to your configuration.
The configuration looks like this (see doc for detailed explanation):
volumes:
- /path/on/your/host:/path/in/your/container
Your configuration would then look like this:
drupal:
image: drupal:8.0.4
volumes:
- /path/on/your/host:/var/www/html
links:
- mysql
cheers,
ceth

Resources