Devilbox: Can't connect to mysql on new install?

Created on 15 Feb 2019  Â·  5Comments  Â·  Source: cytopia/devilbox

ISSUE TYPE

  • Bug Report

Checklist

  • [X] .env file is attached
  • [x] docker-compose.override.yml is attached (if it exists)
  • [x] Custom configs from cfg/ dir are attached (if customized)
  • [x] docker-compose logs and log/ output is added
  • [x] I've looked through the docs: https://devilbox.readthedocs.io/en/latest/

I've looked through existing issues: https://github.com/cytopia/devilbox/issues

OS / ENVIRONMENT

  1. Host operating system and version: Arch Linux 4.20.8-arch1-1-ARCH
  2. Docker version: Docker version 18.09.2-ce, build 62479626f2
  3. Docker Compose version: docker-compose version 1.23.2, build 1110ad01
  4. (Linux) Is SELinux enabled?: No
  5. What git commit hash are you on?: cc6de2dfa187642010585dae7a77b53069fdd97d

SUMMARY

STEPS TO REPRODUCE

Clone the repo, start the project, and try to connect to mysql.

EXPECTED BEHAVIOUR

MySQL is up and accessible

ACTUAL BEHAVIOUR

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

⋊> ~ git clone https://github.com/cytopia/devilbox.git; cd devilbox; cp env-example .env; docker-compose up -d                                                                                                                      11:37:25
Cloning into 'devilbox'...
remote: Enumerating objects: 18633, done.
remote: Total 18633 (delta 0), reused 0 (delta 0), pack-reused 18633
Receiving objects: 100% (18633/18633), 31.08 MiB | 6.22 MiB/s, done.
Resolving deltas: 100% (8063/8063), done.
Creating network "devilbox_app_net" with driver "bridge"
Creating devilbox_bind_1 ... done
Creating devilbox_php_1  ... done
Creating devilbox_httpd_1 ... done
Creating devilbox_memcd_1 ... done
Creating devilbox_redis_1 ... done
Creating devilbox_mongo_1 ... done
Creating devilbox_mysql_1 ... done
Creating devilbox_pgsql_1 ... done
⋊> ~/devilbox on master ◦ ./shell.sh                                                                                                                                                                                                11:37:57

------------------------------------------------------------------------------------------
                              _            _ _ _               
                             | |          (_) | |              
                           __| | _____   ___| | |__   _____  __
                          / _` |/ _ \ \ / / | | '_ \ / _ \ \/ /
                         | (_| |  __/\ V /| | | |_) | (_) >  < 
                          \__,_|\___| \_/ |_|_|_.__/ \___/_/\_\

                                  http://devilbox.org
                            https://devilbox.readthedocs.io



                                    Available Tools
          https://devilbox.readthedocs.io/en/latest/readings/available-tools.html

                           How to work inside this PHP container
 https://devilbox.readthedocs.io/en/latest/intermediate/work-inside-the-php-container.html



                    | Available Dirs   | Description                  |
                    |------------------|------------------------------|
                    | /shared/httpd    | Project base directory       |
                    | /shared/backups  | Backup directory             |
                    | /var/mail        | Email directory              |
                    | /var/log         | Log file directory           |

------------------------------------------------------------------------------------------

[email protected] in /shared/httpd $ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
[email protected] in /shared/httpd $ 

OTHER INFORMATION

Start command

$ docker-compose up -d

File and user permissions (Linux & MacOS)

uid=1000(zack) gid=974(docker) groups=974(docker),998(wheel),1000(zack)
$ ls -la
drwxr-xr-x  4 zack docker  4096 Feb 15 11:37 .devilbox/
⋊> ~/devilbox on master ◦ ls -la data/www/                                                                                                                                                                                          11:40:39
total 8
drwxr-xr-x 2 zack zack   4096 Feb 15 11:37 ./
drwxr-xr-x 7 zack docker 4096 Feb 15 11:37 ../
-rw-r--r-- 1 zack docker    0 Feb 15 11:37 .keepme

logs.tar.gz
docker-compose-log.txt=

documentation invalid mysql

Most helpful comment

FWIW I had exactly the same problem. Happy to find this solution here! The whole Docker thing is awfully confusing for those of us who do not have a lot of experience with it (which is devilbox's target audience, I think). Might be worth mentioning this in the docs.

All 5 comments

@zack6849 MySQL is not running inside the PHP container. You should use:

 mysql -u root -h mysql -p

Info:

When not specifying -h mysql (The host to use, which in this case is called mysql), then the connection defaults to use the local MySQL socket instead of doing a TCP connection. As no MySQL socket is present on the PHP container, the connection will fail. So to overcome this, you must explicitly tell it, to which host to connect.

FWIW I had exactly the same problem. Happy to find this solution here! The whole Docker thing is awfully confusing for those of us who do not have a lot of experience with it (which is devilbox's target audience, I think). Might be worth mentioning this in the docs.

@pnoeric Unfortunately for me it is quite obvious and I am unsure how to best formulate it that it is easy to grasp right from the very beginning. Do you have some description in mind that would have made it very obvious to you?

I would just put a couple of lines in the docs somewhere around where you "use" devilbox (maybe by the part about shell.sh) - "if you want to connect to the MySQL server directly from inside the container, you have to use this special command (so Docker knows to find the server over in its separate, special container)." Something like that. ;-)

I find myself often running shell.sh to drop in and then look at the MySQL server directly from there... so I was stuck until I found this.

Again, I suggest this only because I think your target audience for devilbox seems to be folks (like me) who aren't experts at Docker, so these folks don't really understand the concept of separate-but-linked containers for the various services.

I have rewritten the documentation and hope it does no present what actually needs to be done in Release v1.0.1

https://github.com/cytopia/devilbox/releases/tag/v1.0.1

Was this page helpful?
0 / 5 - 0 ratings