Unbale to find wordpress mysql docker ,succeed connect mysql - 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

Related

Is it possible to see my WordPress database in MySQL workbench when developing locally and using Docker?

I have a docker-compose file that I am using for creating a WordPress environment and it works as expected. I did the docker-compose up and here are my containers:
my containers
and more info about my MySQL container:
MySQL container more info
and my docker-compose content:
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: {}
My question is, how can I possibly see the database in the MySQL workbench application? More precisely which port and hostname and connection type should I use here? I tried everything and couldn't see my db:
MySQL workbench config
Possible duplicate ( How to connect mysql workbench to running mysql inside docker? )
Have you tried:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
or
WORDPRESS_DB_HOST: 127.0.0.1:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress

MySQL on Docker “Connection Refused” despite being able to connect via MySQL Workbench

I’m trying to set up a local dev environment for WordPress with MySQL.
After starting the container, the WordPress element works fine and is accessible.
But MySQL throws connection refused despite being able to connect using the same database details in MySQL Workbench.
I have tried changing the host from dB:3306 to 0.0.0.0:3306 but to no avail.
Using Docker for Mac OS.
Dockerfile:
---
version: '3.3'
services:
db:
image: mysql:5.7.30
volumes:
- ./database:/var/lib/mysql
- ./mysqldumps/production-backup.sql:/docker-entrypoint-initdb.d/production.sql
- ./init/migrate.sh:/docker-entrypoint-initdb.d/migrate.sh
restart: unless-stopped
networks:
- wp
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: $db_root_password
MYSQL_DATABASE: $db_name
MYSQL_USER: $db_user
MYSQL_PASSWORD: $db_password
WORDPRESS_TABLE_PREFIX: $db_table_prefix
PRODUCTION_URL: $production_url
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./wordpress/wp-content:/var/www/html/wp-content
- ./init/prep.sh:/usr/local/bin/prep.sh
ports:
- '80:80'
restart: unless-stopped
networks:
- wp
environment:
WORDPRESS_DB_HOST: $db_host
WORDPRESS_DB_USER: "root"
WORDPRESS_DB_PASSWORD: "password"
WORDPRESS_TABLE_PREFIX: $db_table_prefix
WORDPRESS_DEBUG: $wp_debug_mode
DISABLED_PLUGINS: $wp_plugins_to_disable
networks:
wp:
volumes:
database:
Does anybody have any ideas what’s going on here?

Setup Docker containers for existing Wordpress site

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

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

Issue getting docker to access my database properly with wordpress

I'm new to docker all together - but am trying to setup a local test environment to play with some wordpress things.
So I went to the docker site and pulled up a default docker .yml file on how to get it going easily.
I've made just a couple changes, but mostly this is a straight forward document.
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql2
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: somerootwordpresspw
MYSQL_DATABASE: testdatabase
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
volumes:
- ./WP-TEST/:/var/www/html/
depends_on:
- db
image: wordpress:latest
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
When I run docker-compose up with the above .yml file, I see this error:
MySQL "CREATE DATABASE" Error: Access denied for user 'wordpress'#'%' to database 'wordpress'
Which I find odd, because I'm naming the database testdatabase, so why is it trying to create a database named wordpress?
When I connected with SQL Pro, I could see testdatabase, but according to the console it's trying to create wordpress db.
How do I get it to connect to my named DB, instead of constantly failing to create wordpress?
So I think I got it.
It was really simple. In my wordpress portion of my .yml file I needed to include WP_DB_NAME: testdatabase
By doing that, it used my named testdatabase to install wordpress to.
Hope this helps people who might stumble across this.
Now the .yml file looks like this:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql2
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: somerootwordpresspw
MYSQL_DATABASE: testdatabase
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
volumes:
- ./WP-TEST/:/var/www/html/
depends_on:
- db
image: wordpress:latest
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: testdatabase
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data: