Setup Docker containers for existing Wordpress site - mysql

I'm trying to setup a dev environment for an existing wordpress website hosted on cPanel.
I've exported the test data from the existing pre-production database to be imported into the mysql running in one of the containers.
version: '3.3'
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: P#ssw0rd
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
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:
- /local/path/to/wordpress/src/:/var/www/html
volumes:
db_data: {}
everything starts up fine. Now I'm inserting the db dump into the mysql db in the container
cat dump.sql | docker exec -i docker_db_1 /usr/bin/mysql -u wordpress --password=wordpress wordpress
which finishes without error. When trying to access the website now on localhost:8000 the Apache Ubuntu default page pops up but I can't see anything from the existing wordpress site.

This setup worked for me
docker-compose.yml
version: '3.6'
services:
wordpress:
image: wordpress:${WORDPRESS_VERSION}
container_name: wordpress
volumes:
- ${WORDPRESS_DATA_DIR}:/var/www/html
environment:
- WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}
- WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST}
- WORDPRESS_DB_USER=${WORDPRESS_DB_USER}
- WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
depends_on:
- mysql
restart: always
mysql:
image: mysql:${MYSQLDB_VERSION}
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
- ./mysql_config:/tmp/mysql_config
nginx:
image: nginx:${NGINX_VERSION:-latest}
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- ${NGINX_CONF_DIR}:/etc/nginx/conf.d
- ${NGINX_LOG_DIR}:/var/log/nginx
- ${WORDPRESS_DATA_DIR}:/var/www/html
depends_on:
- wordpress
restart: always
All used variables are set as environment variables first.
To connect to any container with use the following command:
docker exec -i -t <wordpress|mysql|nginx> /bin/bash

Related

Docker: Can't login in my mariadb using phpmyadmin

I am trying to build up a docker-compose file to run all components I need for my app. The app, mysql (mariadb) and phpmyadmin is running but I can't login to my database.
Following docker-compose.yml:
version: '3.7'
networks:
laravel:
services:
php:
image: php:7.4-fpm
build: .conf/php/
restart: always
ports:
- '9000:9000'
working_dir: /var/www
volumes:
- ./src:/var/www
- .conf/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
- .conf/php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini
networks:
- laravel
fpm:
image: php:7.4-fpm
restart: always
volumes:
- ./src:/var/www
networks:
- laravel
nginx:
image: nginx:latest
ports:
- 8000:80
volumes:
- ./src:/var/www
- ./var/log/nginx:/var/log/nginx
- .conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laravel
mariadb:
image: mariadb:latest
ports:
- 3306:3306
volumes:
- mariadb-volume:/var/lib/mysql
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_DATABASE: app
MYSQL_USER: admin
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
phpmyadmin:
image: phpmyadmin
container_name: pma
environment:
MYSQL_DATABASE: app
PMA_HOST: mariadb
depends_on:
- mariadb
ports:
- '8081:80'
networks:
- laravel
volumes:
mariadb-volume:
When I try to login, I get the following error:
mysqli::real_connect(): (HY000/1045): Access denied for user 'admin'#'172.31.0.6' (using password: YES)
I tried to find a solution.. something like set up the right env vars for mysql or set up a bridge between mysql and phpmyadmin. I did the network bridge and I can't really see the problem with my env vars.
Any clue?
System: Windows 10
Edit:
Found the problem. I just did docker-compose down -v ( -v = Remove named volumes declared in the volumes section of the Compose file and anonymous volumes )
and it worked :)
May be you can set for phpmyadmin by this command:
phpmyadmin:
image: phpmyadmin:latest
container_name: pma
restart: always
environment:
MYSQL_DATABASE: app
PMA_HOST: mariadb
depends_on:
- mariadb
ports:
- '8081:80'
networks:
- laravel

Unbale to find wordpress mysql docker ,succeed connect mysql

i install wordpress with docker ,and mysql connected successfully,but i can't find my wordpress mysql data . i use mysql client to connet mysql server docker ,i can't find data.
version: "3.9"
services:
db:
container_name: mysql-bbpress-compose
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1234567
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
container_name: wrodpress-bbpress-compose
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- "1080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
enter image description here
I can't fidn DB wordpress

mysql database name and credentials inside docker container not updating

I have a LAMP stack with laravel setup in docker-compose containers,everything seems to be working fine so far. I initially had a test database with the name of homestead setup in docker-compose.yml that was just there for testing now i want to change it to something more meaningful like my project name. let me show you my docker-compose.yml
version: '3'
networks:
laravel:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- 80:80
volumes:
- ./src:/var/www/html:delegated
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: alis
MYSQL_USER: alis
MYSQL_PASSWORD: pass
MYSQL_ROOT_PASSWORD: pass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ./src:/var/www/html:delegated
networks:
- laravel
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
user: laravel
entrypoint: ['composer', '--ignore-platform-reqs']
networks:
- laravel
npm:
image: node:latest
container_name: npm
volumes:
- ./src:/var/www/html
ports:
- 3000:3000
- 3001:3001
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html:delegated
depends_on:
- mysql
working_dir: /var/www/html
user: laravel
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
container_name: phpmyadmin
depends_on:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
the problem is phpmyadmin is still using the old database and credentials , it tried the following solutions
docker-compose down
docker-compose down -v
then
docker-compose up -d
this didnt work.Out of frustration even thought this is probably not the best way to do it, I removed all containers, all images and then ran
docker-compose up -d
to re-install everything from scratch to my surprise phpmyadmin still picks up the old database config.Does anyone know the reason for this behaviour?
Your phpmyadmin service tries to connect as root:secret (MYSQL_ROOT_PASSWORD) while your mysql service defines root:pass (MYSQL_ROOT_PASSWORD) as admin user.
See the available configuration here:
https://hub.docker.com/_/phpmyadmin
https://hub.docker.com/_/mysql

mysql docker cannot connect from outside container

I've created a docker-compose file for PHP dev but I cannot connect to the DB with sequel pro neither from the APP.
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
ports:
- "80:80"
- "443:443"
networks:
- app-network
#MySQL Service
db:
image: mysql:latest
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
expose:
# Opens port 3306 on the container
- '3306'
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laraveluser
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
everything works OK and no errors are displayed but when I'm trying to connect to the DB in any way it doesn't work docker-compose exec app PHP artisan migrate nor with sequel Pro, what's wrong with my config?
The only way to access the DB is with docker-compose exec db bash
here the full repo
straight from the GitHub repo I have the answer, though I haven't tried yet as I think I'm going to stick with 5.7 for now.
You might need to add --default-auth=mysql_native_password to your command
Mysql:8 uses caching_sha2_password by default https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
#454 (comment)
After digging into your code, I found that you need to update .env.example file
Replace DB_HOST=db on line 10.
You must have missed it, but it is already mentioned in the post that you had referred, under the heading "Step 8 — Modifying Environment Settings and Running the Containers".

Access mysql db inside docker container from outside

I'm learning to use docker to make my development easier but I'm still failing access mysql.
Here is my docker-compose.yaml:
version: '3.3'
services:
# Database
db:
image: mysql:latest
ports:
- '3306:3306'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: dev1
MYSQL_USER: root
MYSQL_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: root
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: dev1
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
Wordpress is running without difficulties which means that mysql must be alright too. I'm on Linux and trying to connect database via mysql workbench. It appears that connection is also ok expect for, there is no schema and so no wordpress tables.
I tried to add also phpmyadmin into docker-compose.yaml:
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
but here I get following error after attempt to access db:
What I miss?
EDIT:
here is overview of running containers:
So i modified your docker-compose , with 2 small changes , and i dont have a issue .
I created a user for wordpress ( userdev1 ) in mysql .
The root is already here and can have some restrictions for remote access .
Via phpmyadmin i can login with userdev1 or root
You want a network access with the root account you must set this variable
MYSQL_ROOT_HOST .
You can find more information on this page (
https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/docker-mysql-more-topics.html#docker_var_mysql-root-host )
version: '3.3'
services:
# Database
db:
image: mysql:5.7
ports:
- '3306:3306'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password4root
MYSQL_DATABASE: dev1
MYSQL_USER: userdev1
MYSQL_PASSWORD: password4dev1
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: userdev1
WORDPRESS_DB_PASSWORD: password4dev1
WORDPRESS_DB_NAME: dev1
networks:
- wpsite
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
** UPDATED **
With the very last version of mysql docker image ( aka mysql 8.0 ),
you must change the default-authentification to mysql_native_password to be comptatible with legacy mysql client
source :
https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password