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
Related
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
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.
I'm a newbie when it comes to Docker. For my setup I'm installing Docker for the purpose of running a MySQL WordPress on a MacOS environment.
Below is my docker-compose.yml file:
wordpress:
image: wordpress
links:
- wordpress_db:mysql
ports:
- 8080:80
wordpress_db:
image: mariadb
phpmyadmin:
image: corbinu/docker-phpmyadmin
links:
- wordpress_db:mysql
ports:
- 8181:80
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=wordpress_db
- MYSQL_USER=sbroot
- MYSQL_PASSWORD=root
Is docker-compose up -d to terminal the correct approach? Also, are there any alternatives to using Docker to achieve the same result?
I don't know whether you add it or not, but you have to put the following lines on top of your docker-compose.yml file:
version: '3'
services:
What I can see in your file, two database images, 1) mysql and 2) mariaDb. You should keep only one of those for e.g. mysql for instance.
And what error do you get, when you visit link, http://localhost:8081 ?
I have all set in my local machine for virtual machine shared folders. I have following code in my Docker compose file for Wordpress service. but not sure how the volumes work here. Can you please explain?
version: '2'
services:
database:
image: mysql:5.6
volumes:
- ./mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
restart: unless-stopped
wordpress:
image: wordpress:4.9.6
ports:
- 49160:80
links:
- database:mysql
volumes:
- ./wordpress:/var/www/html/wp-content
environment:
WORDPRESS_DB_PASSWORD: password
restart: unless-stopped
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- database:db
ports:
- 8080:80
Does the above volumes line of code mean, does it need to create a WordPress folder in my docker-compsose.yml file that I am currently running?
Or is it anyhow related to my shared folders in virtual machine?
Basically volumes are instruments for Docker so it can retain data. Docker containers are generally designed to be stateless, but if you need to retain state/information between runs, that's where volumes come in.
You can create an unnamed volume in the following way:
volumes:
- /var/www/html/wp-content
This will retain your wp-content folder in the internal volumes storage without a particular name.
A second way would be to give it a name, making it a named volume:
volumes:
- mywp:/var/www/html/wp-content
And the final type, which is also what you are doing, is called a Volume Bind. This basically binds/mounts the content of a folder on your host machine in the container. So if you change a file in either place, it will be saved on the other.
volumes:
- ./wordpress:/var/www/html/wp-content
In order to use your Volume Bind, you will need to create the folder "wordpress" in the folder where you're running the docker-compose.yaml (usually your root folder). Afterwards, when your installation changes within the container, it will also change on the bind and vice-versa.
EDIT: In your particular case the following should work:
version: '3.2'
services:
database:
image: mysql:5.6
volumes:
- ./mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
restart: unless-stopped
wordpress:
image: wordpress:4.9.6
ports:
- 49160:80
links:
- database:mysql
volumes:
- type: bind
source: ./wordpress
target: /var/www/html/wp-content
environment:
WORDPRESS_DB_PASSWORD: password
restart: unless-stopped
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- database:db
ports:
- 8080:80
Adding a volume to your docker-compose.yml file will enable you to 'mount' content from your local file system into the running container.
So, about the following line here:
volumes:
- ./wordpress:/var/www/html/wp-content
This means that whatever's in your local wordpress directory will be placed in the /var/www/html/wp-content directory inside your container. This is useful because it allows you to develop themes and plugins locally and automatically inject them into the running container.
To avoid confusion, I'd recommend renaming wordpress to something else, so it's clear that you're mounting only your WordPress content, and not core files themselves.
I have a similar setup here, in case you need another reference:
https://github.com/alexmacarthur/wp-skateboard
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.