I am having a WordPress site that runs using xampp , now I want to run that in docker
this is my docker-compose file
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
wordpress:
build: .
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpress
volumes:
["./:/var/www/html"]
depends_on:
- db
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
PMA_USER: wordpress
PMA_PASSWORD: password
ports:
- "8081:80"
volumes:
mysql: {}
-----------------------------------------------------------------------------
this is my docker file
FROM php:7.4-apache
# copy the WordPress files to the web root
COPY . /var/www/html/
# set the working directory to the web root
WORKDIR /var/www/html/
# set file permissions
RUN chown -R www-data:www-data /var/www/html/
# expose port 80 for the web server
EXPOSE 80
I have a WordPress site in my locally that run in xampp, I want to change that to a docker container
Related
I've created a docker-composer.yml file to run a container for wordpress mysql and phpmyadmin. It starts well bt i have a permission problem. All my files have www-data:www-data for user and group and when i want to create a new theme in wp-content i have a permission denied. Im in ubuntu 18.04.
here is my docker-compose.yml file :
version: '3'
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes: ['./:/var/www/html']
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
i tried to change to "chown -Rf myname:myname ." so there i can create a file but upload for files in wordpress doesn't work now. So i wonder how to set properly permissons with a docker mounted volume in ubuntu.
I just add user: 1000:1000 to container, and everything works fine. Got idea from this tutorial
One solution for this would be to add your own user myname to the www-data group
sudo usermod -aG www-data myname
and make sure the www-data group has write privileges on all files/directories and execute privileges on directories.
Another solution would be to let your own user own all files (myname:www-data as owner) and directories and make sure www-data group has appropriate read/write privileges so the WordPress container's webserver can use the group privileges to read/write files.
Off-topic: also make sure to have a
define('FS_METHOD', 'direct');
line in your wp-config.php.
I made the wp site on my local mac using localhost. Then I git commited the entire thing and transferred to my hosting using http://ip:port instead of localhost. Then I edited wp-config define('DOMAIN_CURRENT_SITE', 'localhost'); and mySQL tables wp_blogs, wp_site, wp_sitemeta.
Now all the assets still reference localhost instead of http://ip:port so I see the text but no css/js/images.
I'm guessing it's some apache setting problem?
This is my docker compose:
version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./files:/var/www/html
# basic http auth
- ./apache/000-default.conf:/etc/apache2/sites-enabled/000-default.conf
- ./apache/.htpasswd:/etc/apache2/.htpasswd
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: username
WORDPRESS_DB_PASSWORD: password
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: username
MYSQL_USER: username
MYSQL_PASSWORD: password
I tried finding what is referencing localhost in apache config but
cat `grep -rl localhost /etc/apache2` | grep localhost
finds nothing useful.
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
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/
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.