Jump to content

I have an Unraid NAS and I want to run a MySQL database from it via docker for a WordPress site I'm working on. I pulled the MySQL docker and according to the documentation on Docker Hub, I just run `docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag` when I run that, (with the password and database name instead of placeholders) it does create the database but I don't know what the username is. Wordpress is running in a different docker container and won't accept the username root with the password I made. What would the username be?

Link to comment
Share on other sites

Link to post
Share on other sites

57 minutes ago, zhnu said:

The containers should be run on the same network root is the user the command is wrong should be:
 


docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest

The name is the hostname of the container in question so on wordpress instance you should config in this case to connect to :
url:
some-mysql:3306
user: root
password: my-secret-pw

Quick reminders:
  You should not use root as the db user for services, create another one with proper credentials and roles.
  You should use docker secrets to define sensitive data.
  Usually DB performance on containers takes a large hit.

 

That didn't work. I recreated the container with the command you gave and WordPress doesn't accept it even with that URL and username. If it helps, the fields in the WordPress thing are Database Name, Username, Password, Database Host, and Table Prefix instead of URL, User, and root. Not sure if that makes any difference but. Maybe there is some other issue?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

Have you created the database?

I ran the docker run command. Does that create the database or do I need to do something else?

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, zhnu said:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=wordpress -d mysql:latest

This will create a database named wordpress when you start, or you can do it by hand inside the container.
 


docker ps
# This will show you running instances
docker exec -it somerandomID /bin/sh mysql
# This will bring up an interactive shell that's running inside the container.
Now inside the container you can run mysql commands

 

When I do the docker exec, it returns /bin/sh: 0: Can't open mysql

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, zhnu said:

okay run only
 


docker exec -it somerandomID /bin/sh

and then when inside:

mysql

Returned this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

mysql -uroot -p"$MYSQL_ROOT_PASSWORD"

Returned this:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, zhnu said:

now type:

CREATE DATABASE wordpress;

Edit: Returned this, Wordpress still isn't accepting the following:

Database Name: wordpress

Username: root

Password: (root password)

Database Host wordpress:3306

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.85 sec)
Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

Okay now you have a database :)

Database Name: wordpress
Username: root
Password: my-secret-pw
Database Host: some-mysql

Still no - if it matters, the some-mysql is Webdata. Also - does it matter that the pw has symbols?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

Nope password should can and should have symbols, does wordpress show you an error?

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at Webdata. This could mean your host’s database server is down.

  • Are you sure you have the correct username and password?
  • Are you sure you have typed the correct hostname?
  • Are you sure the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

Did you run wordpress with:
 


$ docker run --name some-wordpress --network some-network -d wordpress

If you did this means it's running on a diff network than mysql, to ensure they're both on the same network rerun mysql with.


docker run --name some-mysql --network some-network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=wordpress -d mysql:latest


 

I used

docker run --name Webdata -e MYSQL_ROOT_PASSWORD=(password) -d mysql:latest

Do I need to docker stop and rm the container and do it again or?

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, zhnu said:

You don't need to rm the container. Just stop and run.

 

docker: Error response from daemon: Conflict. The container name "/Webdata" is already in use by container "67a6a371213e6ec513373de2dfa18e488363d308af040e0a2282b25b1bb6aafb". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, zhnu said:

Sorry I don't usually run like this, Try.

docker start --name some-mysql --network some-network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=wordpress -d mysql:latest

Unknown flag `--name`

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, zhnu said:

docker start some-mysql --network some-network -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=wordpress -d mysql:latest

Unknown flag --network

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, zhnu said:

Sorry I thought it could be changed with start seems you really have to recreate it, docker rm etc...

Ok, recreated it. Do I also need to do that for Wordpress?

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, zhnu said:

It should be ok. You really should consider using docker-compose for this make your life alot easier

I think I do need to recreate wordpress - I didn't put a network. How do I use docker compose? Like how do I download it?

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, zhnu said:

Check if it's not already instaled:

docker-compose --version
Here's a simple way:

Create a file named docker-compose.yml
Paste inside:


version: '3.1'

services:

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpressuser
      MYSQL_PASSWORD: examplepass
    volumes:
      - db:/var/lib/mysql
  
  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: wordpressuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: wordpress    
    volumes:
      - wordpress:/var/www/html    

volumes:
  wordpress:
  db:

now inside the dir you have docker-compose.yml


docker-compose up -d


 

Ok so I installed docker compose and then ran the YML file. Here is the output:

Creating network "root_default" with the default driver
Creating volume "root_wordpress" with default driver
Creating volume "root_db" with default driver
Pulling mysql (mysql:5.7)...
5.7: Pulling from library/mysql
6ec7b7d162b2: Already exists
fedd960d3481: Already exists
7ab947313861: Already exists
64f92f19e638: Already exists
3e80b17bff96: Already exists
014e976799f9: Already exists
59ae84fee1b3: Already exists
7d1da2a18e2e: Pull complete
301a28b700b9: Pull complete
979b389fc71f: Pull complete
403f729b1bad: Pull complete
Digest: sha256:d4ca82cee68dce98aa72a1c48b5ef5ce9f1538265831132187871b78e768aed1
Status: Downloaded newer image for mysql:5.7
Creating root_mysql_1     ... done
Creating root_wordpress_1 ... done

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, zhnu said:

Now you should have wordpress running on port 8080.
You can check if it's running also with docker ps.

This is docker container ls --all:

CONTAINER ID        IMAGE                              COMMAND                  CREATED              STATUS                     PORTS                    NAMES
00a458e4c380        mysql:5.7                          "docker-entrypoint.s…"   About a minute ago   Up 53 seconds              3306/tcp, 33060/tcp      root_mysql_1
f5049bfaeba6        wordpress:latest                   "docker-entrypoint.s…"   About a minute ago   Up 55 seconds              0.0.0.0:8080->80/tcp     root_wordpress_1
b8e08b9d3c81        mysql:latest                       "docker-entrypoint.s…"   16 minutes ago       Created                                             wordpress
293a66171d25        wordpress                          "docker-entrypoint.s…"   4 hours ago          Exited (0) 8 minutes ago                            website

Should I just delete all those containers and run the yml file again? (I ran it twice cause i forgot to put the passwords and stuff the first time)

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, zhnu said:

Yes but you'll also need to delete the volumes:


docker stop $(docker ps -q)
docker rm $(docker ps -aq)
docker volume rm $(docker volume ls -q)

Should clean-up nicely

When I go the wordpress address, it says  Error establishing database connection

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, zhnu said:

Did it clean everything up I just ran on my pc and worked right out of the box

 Yeah it deleted all the docker containers so I just ran the yml again.

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, zhnu said:

Try this I think I might be restarting before you get a chance to delete it the docker-compose down should stop it correctly:

 


docker-compose down
docker stop $(docker ps -q)
docker rm $(docker ps -aq)
docker volume rm $(docker volume ls -q)

 

So I did all of that but the last one because not I am not in the normal terminal, there is a > insead of root@NAS

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, zhnu said:

The lastone removes the volumes that were previously created so it deletes any data that was persisted on the docker instances

docker volume rm $(docker volume ls -q)

K did that

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, zhnu said:

docker-compose up -d

And after it starts should be OK on port 8080. Mine showed setup and completed setup successfully.

Still the same thing.

version: '3.1'

services:

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ******
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpressuser
      MYSQL_PASSWORD: *******
    volumes:
      - db:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: wordpressuser
      WORDPRESS_DB_PASSWORD: *******
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html

volumes:
  wordpress:
  db:

Is that right? ^

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, zhnu said:

Yes it seems Okay.
Mmmm try cleanup and start again with the passwords with simple values.
I think there're some special characters like $ have to be duplicated on docker-compose. Just for tryout purposes try simple passwords just to discard the possibility.
 

Oh - I think by browser is caching something - works in Google Chrome. I will just use Chrome until the cache expires. I will also reset DNS cache just in case.

Link to comment
Share on other sites

Link to post
Share on other sites

15 hours ago, zhnu said:

Just glad it works man.

Didn't see your reply - Thanks for your help!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×