Score:0

Cannot access mysql in new docker/docksal/d9 installation

cl flag

I had a D9 installation running in MacPorts. I installed docker and docksal, copied the D9 project to the docksal project folder, and uninstalled MacPorts.

Docksal starts up like this:

Starting services...
Creating network "myproject_default" with the default driver
Starting myproject_db_1  ... done
Starting myproject_cli_1 ... done
Starting myproject_web_1 ... done
Connected vhost-proxy to "myproject_default" network.

docker ps yields:

CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS                    PORTS                                                    NAMES
13ef8d52170d   docksal/ssh-agent:1.3     "docker-entrypoint.s…"   11 minutes ago   Up 11 minutes (healthy)                                                            docksal-ssh-agent
f68c8343b0fe   docksal/dns:1.1           "docker-entrypoint.s…"   11 minutes ago   Up 11 minutes (healthy)   0.0.0.0:53->53/udp                                       docksal-dns
94854d2add70   docksal/vhost-proxy:1.7   "docker-entrypoint.s…"   11 minutes ago   Up 11 minutes (healthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp                 docksal-vhost-proxy
17b4ab7d12dc   docksal/mysql:5.7-1.5     "docker-entrypoint.s…"   17 minutes ago   Up 10 minutes (healthy)   33060/tcp, 0.0.0.0:55001->3306/tcp, :::55001->3306/tcp   myproject_db_1
a70ffb3c287a   docksal/apache:2.4-2.3    "httpd-foreground"       34 minutes ago   Up 10 minutes (healthy)   80/tcp, 443/tcp                                          myproject_web_1
7e331d850e06   docksal/cli:php7.4-3.0    "/opt/startup.sh sup…"   34 minutes ago   Up 10 minutes (healthy)   22/tcp, 3000/tcp, 9000/tcp                               myproject_cli_1'

but fin drush cr yields:

    In Connection.php line 174:
                                                        
      SQLSTATE[HY000] [2002] No such file or directory  
                                                    
and fin drush sqlc yields:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

In Process.php line 256:
                                                                                                     
  The command "mysql --defaults-file=/tmp/drush_RPHXDD --database=myproj --host=localhost --port=33  
  06 -A" failed.                                                                                     
                                                                                                     
  Exit Code: 1(General error)                                                                        
                                                                                                     
  Working directory: /var/www/docroot                                                                
                                                                                                     
  Output:                                                                                            
  ================                                                                                   
                                                                                                     
                                                                                                     
  Error Output:                                                                                      
  ================                                                                                   
                                    

fin drush status:

 Drupal version : 9.1.2                                 
 Site URI       : http://myproject.docksal            
 DB driver      : mysql                                 
 DB hostname    : localhost                             
 DB port        : 3306                                  
 DB username    : root                                  
 DB name        : myproj                                
 PHP binary     : /usr/local/bin/php                    
 PHP config     :                                       
 PHP OS         : Linux                                 
 Drush script   : /usr/local/bin/drush                  
 Drush version  : 10.5.0                                
 Drush temp     : /tmp                                  
 Drush configs  : /var/www/vendor/drush/drush/drush.yml 
 Drupal root    : /var/www/docroot                      
 Site path      : sites/default              

docker logs db:

db_1   | Version: '5.7.30'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
db_1   | 2021-08-08T05:01:53.500160Z 0 [Note] Giving 0 client threads a chance to die gracefully
db_1   | 2021-08-08T05:01:53.500184Z 0 [Note] Shutting down slave threads
db_1   | 2021-08-08T05:01:53.500188Z 0 [Note] Forcefully disconnecting 0 remaining clients
db_1   | 2021-08-08T05:01:53.500192Z 0 [Note] Event Scheduler: Purging the queue. 0 events
db_1   | 2021-08-08T05:01:53.500260Z 0 [Note] Binlog end
db_1   | 2021-08-08T05:01:53.500640Z 0 [Note] Shutting down plugin 'ngram'
db_1   | 2021-08-08T05:01:53.500647Z 0 [Note] Shutting down plugin 'partition'
db_1   | 2021-08-08T05:01:53.500649Z 0 [Note] Shutting down plugin 'BLACKHOLE'
db_1   | 2021-08-08T05:01:53.500652Z 0 [Note] Shutting down plugin 'ARCHIVE'
db_1   | 2021-08-08T05:01:53.500654Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
db_1   | 2021-08-08T05:01:53.500677Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
db_1   | 2021-08-08T05:01:53.500679Z 0 [Note] Shutting down plugin 'MyISAM'
db_1   | 2021-08-08T05:01:53.500686Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
db_1   | 2021-08-08T05:01:53.500689Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
db_1   | 2021-08-08T05:01:53.500691Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
db_1   | 2021-08-08T05:01:53.500692Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
db_1   | 2021-08-08T05:01:53.500694Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
db_1   | 2021-08-08T05:01:53.500695Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
db_1   | 2021-08-08T05:01:53.500697Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
db_1   | 2021-08-08T05:01:53.500698Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
db_1   | 2021-08-08T05:01:53.500700Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
db_1   | 2021-08-08T05:01:53.500701Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
db_1   | 2021-08-08T05:01:53.500703Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
db_1   | 2021-08-08T05:01:53.500704Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
db_1   | 2021-08-08T05:01:53.500706Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
db_1   | 2021-08-08T05:01:53.500707Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
db_1   | 2021-08-08T05:01:53.500709Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
db_1   | 2021-08-08T05:01:53.500710Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
db_1   | 2021-08-08T05:01:53.500712Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
db_1   | 2021-08-08T05:01:53.500713Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
db_1   | 2021-08-08T05:01:53.500714Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
db_1   | 2021-08-08T05:01:53.500716Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
db_1   | 2021-08-08T05:01:53.500717Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
db_1   | 2021-08-08T05:01:53.500719Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
db_1   | 2021-08-08T05:01:53.500720Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
db_1   | 2021-08-08T05:01:53.500722Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
db_1   | 2021-08-08T05:01:53.500723Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
db_1   | 2021-08-08T05:01:53.500725Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
db_1   | 2021-08-08T05:01:53.500726Z 0 [Note] Shutting down plugin 'INNODB_CMP'
db_1   | 2021-08-08T05:01:53.500728Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
db_1   | 2021-08-08T05:01:53.500729Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
db_1   | 2021-08-08T05:01:53.500730Z 0 [Note] Shutting down plugin 'INNODB_TRX'
db_1   | 2021-08-08T05:01:53.500732Z 0 [Note] Shutting down plugin 'InnoDB'
db_1   | 2021-08-08T05:01:53.500829Z 0 [Note] InnoDB: FTS optimize thread exiting.
db_1   | 2021-08-08T05:01:53.500933Z 0 [Note] InnoDB: Starting shutdown...
db_1   | 2021-08-08T05:01:53.601593Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
db_1   | 2021-08-08T05:01:53.602156Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 210808  5:01:53
db_1   | 2021-08-08T05:01:55.139112Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12488783
db_1   | 2021-08-08T05:01:55.147075Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
db_1   | 2021-08-08T05:01:55.147420Z 0 [Note] Shutting down plugin 'MEMORY'
db_1   | 2021-08-08T05:01:55.147516Z 0 [Note] Shutting down plugin 'CSV'
db_1   | 2021-08-08T05:01:55.147588Z 0 [Note] Shutting down plugin 'sha256_password'
db_1   | 2021-08-08T05:01:55.147917Z 0 [Note] Shutting down plugin 'mysql_native_password'
db_1   | 2021-08-08T05:01:55.148232Z 0 [Note] Shutting down plugin 'binlog'
db_1   | 2021-08-08T05:01:55.155374Z 0 [Note] mysqld: Shutdown complete
db_1   | 
db_1   | 2021-08-08 05:02:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1   | 2021-08-08 05:02:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1   | Running init scripts in /docker-entrypoint.d/ as root...
db_1   | Including custom configuration from /var/www/.docksal/etc/mysql/my.cnf
db_1   | 2021-08-08 05:02:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1   | 2021-08-08T05:02:04.376939Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2021-08-08T05:02:04.381332Z 0 [Note] mysqld (mysqld 5.7.30) starting as process 1 ...
db_1   | 2021-08-08T05:02:04.384729Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1   | 2021-08-08T05:02:04.384742Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2021-08-08T05:02:04.384744Z 0 [Note] InnoDB: Uses event mutexes
db_1   | 2021-08-08T05:02:04.384747Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1   | 2021-08-08T05:02:04.384749Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2021-08-08T05:02:04.384751Z 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2021-08-08T05:02:04.385017Z 0 [Note] InnoDB: Number of pools: 1
db_1   | 2021-08-08T05:02:04.385113Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2021-08-08T05:02:04.386353Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
db_1   | 2021-08-08T05:02:04.490032Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2021-08-08T05:02:04.507421Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2021-08-08T05:02:04.533356Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2021-08-08T05:02:04.618195Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2021-08-08T05:02:04.618496Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2021-08-08T05:02:04.751813Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2021-08-08T05:02:04.777613Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1   | 2021-08-08T05:02:04.777675Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1   | 2021-08-08T05:02:04.810394Z 0 [Note] InnoDB: 5.7.30 started; log sequence number 12488783
db_1   | 2021-08-08T05:02:04.832602Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2021-08-08T05:02:04.834210Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2021-08-08T05:02:04.898552Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210808  5:02:04
db_1   | 2021-08-08T05:02:04.914468Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1   | 2021-08-08T05:02:04.915086Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1   | 2021-08-08T05:02:04.925715Z 0 [Warning] CA certificate ca.pem is self signed.
db_1   | 2021-08-08T05:02:04.926091Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1   | 2021-08-08T05:02:04.932524Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1   | 2021-08-08T05:02:04.932753Z 0 [Note] IPv6 is available.
db_1   | 2021-08-08T05:02:04.932880Z 0 [Note]   - '::' resolves to '::';
db_1   | 2021-08-08T05:02:04.933009Z 0 [Note] Server socket created on IP: '::'.
db_1   | 2021-08-08T05:02:04.950069Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1   | 2021-08-08T05:02:05.120498Z 0 [Note] Event Scheduler: Loaded 0 events
db_1   | 2021-08-08T05:02:05.134073Z 0 [Note] mysqld: ready for connections.
db_1   | Version: '5.7.30'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

This is the case whether I have localhost or 127.0.0.1 in settings.php. Seems the mysql service is there and the container is starting, but nothing can connect to the service.

cn flag
Would the DB really be on localhost for a containerised solution? Doesn’t that kind of defeat the purpose?
cl flag
I assume localhost to be relative to the container, as is /var/www/html
cn flag
They’re different machines so I’m not sure that assumption would hold. Admittedly I haven’t used Docksal (Lando is hard to beat for reliability and ease of use), but I would’ve assumed they work similarly. Especially as both create a network so that the containers can communicate with one another, which would be unnecessary if they’re reachable by the same host name
cl flag
You’re correct. I ran the install again, with a different result, that being the connection works. Since you put me on that course, please take your first comment and paste it as the answer along with: It should be ‘db’ instead of ‘localhost’.
Kevin avatar
in flag
You'll have to refer to the Docker docs for all this. This is core Docker functionality, not specific to Drupal. The internal network in Docker can see containers by their name.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.