Docker Compose FIle For Wordpress, MySQL & phpmyadmin
source link: https://gist.github.com/bradtraversy/faa8de544c62eef3f31de406982f1d42
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Wordpress & Docker
This file will setup Wordpress, MySQL & PHPMyAdmin with a single command. Add the code below to a file called "docker-compose.yaml" and run the command
$ docker-compose up -d
# To Tear Down
$ docker-compose down --volumes
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:
How would I install an SSL certificate on that thingy?
nickkostov commented on Dec 28, 2020 •
`services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: username
MYSQL_PASSWORD: password
networks:
- wpsite
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '7555:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '80:80'
restart: always
volumes: ['./:/var/www/html']
volumes:
- ./apache2:/etc/apache2
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:`
JayGervais commented on Jan 18, 2021 •
Thanks for this. Would I just add this as a yaml file to the same directory as my working files to start? Cheers!
This guy must be canonized. Thanks
this does not work for creating themes and plugins.
Permission error
Hey guys, I need your help with running it on digitalocean. ones i copied over file and run
docker-compose up -d
i can access wordpress using my digitalocen ip and port 8000. I was trying to set up nginx as reverse proxy for access it by domain name directly but no luck. Could any one help me?
Hi ibenzyk, I have the same issue as you. I wasn't able to setup host name to this wordpress. Did you get any luck setting it up?
Hi together, I am using this compose file for several months and, first of all, thanks a lot. I have been recently trying to have multiple wordpress container running on different ports but always some errors. Changing just the ports is not enough. Always DB problems.
How can I have another wp container running on different ports and DB? Thanks
add WORDPRESS_DB_NAME in last section in case you have db connection issue:
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
WORDPRESS_DB_NAME: wordpress
networks:
- wpsite
Everything here is unsecure. I think for production, we need to have all three MySQL, phpmyadmin and Wordpress over SSL. do you have example for that?
- image: phpmyadmin/phpmyadmin
+ image: phpmyadmin
We have an official image, that will add some more security (official images scripts are audited before they go into the registry) ;)
if you start the container for the first time it can throw you Error establishing a database connection
, to overcome this issue just stop the container and start again and it will work.
Those of you are having trouble with database connection, try this. https://github.com/IamLizu/wp-docker/blob/master/docker-compose.yml.
You are getting the error because the database name is not specified in WordPress environment. Also, I have moved the credentials to .env
and fixed the local file mapping to container which exposes docker-compose file.
docker-compose down seems to destroy the DB and I get wordpress install next time I do docker-compose up -d
Any way to fix this?
williamdes commented on Aug 5, 2021 •
docker-compose down seems to destroy the DB and I get wordpress install next time I do docker-compose up -d
Any way to fix this?
Add a volume to db ;)
volumes:
- db_data:/var/lib/mysql
volumes:
- ./db-folder-data:/var/lib/mysql
docker-compose down seems to destroy the DB and I get wordpress install next time I do docker-compose up -d
Any way to fix this?Add a volume to db ;)
volumes: - db_data:/var/lib/mysql
volumes: - ./db-folder-data:/var/lib/mysql
Thanks @williamdes I already used that
volumes:
- db_data:/var/lib/mysql
but now it woks and does not seem to delete the db. Not sure what the problem was.
Thanks anyway!
Prem1605 commented on Aug 25, 2021 •
After Troubleshooting. The web app is working.
The URL opens only PhpMyAdmin. How can I see Wordpress.??
Why is no volume line for the phpmyadmin.?
docker-compose down seems to destroy the DB and I get wordpress install next time I do docker-compose up -d
Any way to fix this?Add a volume to db ;)
volumes: - db_data:/var/lib/mysql
volumes: - ./db-folder-data:/var/lib/mysql
Thanks @williamdes I already used that
volumes:
- db_data:/var/lib/mysql
but now it woks and does not seem to delete the db. Not sure what the problem was.
Thanks anyway!
Why is no Volumes defined for phpmyadmin.??
Why is no Volumes defined for phpmyadmin
phpMyAdmin does not need a volume, it's only a GUI
Why is no Volumes defined for phpmyadmin
phpMyAdmin does not need a volume, it's only a GUI
Thankyou.
After Deploying this yml file to Azure web app. I click on the URL and I am able to access only phpmyadmin. how to access wordpress.??
I keep getting an error after running the command '' docker-compose up -d ''
Error
'' Error response from daemon: can't access specified distro mount service: stat /run/guest-services/distro-services/debian.sock: no such file or directory "
Are we certain that docker-compose down --volumes
is the correct command to use in order to stop the container? After some tinkering, I have found that the "down" command will delete all of your volumes which leaves you with installing WP each time you run "docker-compose up -d".
So far, I have found a better solution of using docker-compose stop
and docker-compose start
after initially running docker-compose run -d
command
my man! many thanks!!
Nigrimmist commented on Apr 28 •
Still had a Database connection error. Working docker-compose for me :
version: '2'
services:
wordpress:
depends_on:
- db
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: admin
WORDPRESS_DB_PASSWORD: admin
WORDPRESS_DB_NAME: wordpress
ports:
- 8082:80
networks:
- myNetwork
db:
image: mysql
restart: always
volumes:
- ./database:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: wordpress
MYSQL_USER: admin
MYSQL_PASSWORD: admin
networks:
- myNetwork
phpmyadmin:
depends_on:
- db
image: phpmyadmin
restart: always
ports:
- 8083:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: admin
networks:
- myNetwork
networks:
myNetwork:
volumes:
database:
Please use image: phpmyadmin
instead of image: phpmyadmin/phpmyadmin
Yeap, updated
Alguien sabe si puedo modificar los puertos de BD por ejemplo se que ocupa 3306 y reemplazarlos por 1200 si se puede alguien me puede ayudar?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK