Suite unable to connect to database from docker container

I’m trying to dockerize our version of suite and I’m getting the following exception recorded in the suite log:
[2023-07-14 22:07:31] request.CRITICAL: Uncaught PHP Exception mysqli_sql_exception: “No such file or directory” at /var/www/html/SuiteCRM/public/legacy/include/database/MysqliManager.php line 325 {“exception”:“[object] (mysqli_sql_exception(code: 2002): No such file or directory at /var/www/html/SuiteCRM/public/legacy/include/database/MysqliManager.php:325)”} []

Here is the same exception on the PHP log:

I’m not getting any issues running this outside of docker

Currently running PHP8.1, SuiteCRM 8.2.4, MySQL

This is what is currently in my dockerfile:

FROM ubuntu:latest

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt -y upgrade

RUN apt-get install apache2 -y

RUN apt -y install ca-certificates apt-transport-https software-properties-common

RUN add-apt-repository ppa:ondrej/php

RUN apt-get -y update

RUN apt-get install -y --no-install-recommends php8.1 libapache2-mod-php8.1

RUN apt-get install -y php8.1-fpm libapache2-mod-fcgid

RUN apt-get install -y php8.1-mysql

RUN apt-get install -y php8.1-curl php8.1-gd php8.1-zip php8.1-xml php8.1-mbstring php8.1-intl php8.1-simplexml php8.1-dom php8.1-ldap php8.1-imap

RUN a2enmod rewrite

RUN a2enconf php8.1-fpm

RUN apt install -y zlib1g-dev libxml2-dev

RUN apt-get update && apt-get upgrade -y && \

apt-get install -y nodejs \

npm

RUN npm install --global yarn

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

COPY ./ /var/www/html/SuiteCRM/

WORKDIR /var/www/html/SuiteCRM/

RUN mv ./docker/config/apache/apache2.conf /etc/apache2/apache2.conf

RUN mv ./docker/config/apache/sites.conf /etc/apache2/sites-enabled/apache2.conf

RUN mv ./docker/config/php/php.ini /etc/php/8.1/apache2/php.ini

RUN rm -r ./docker

RUN composer install

RUN yarn

RUN yarn build

CMD [“apachectl”, “-D”, “FOREGROUND”]

EXPOSE 80

My apache sites config:

<VirtualHost *:80>
<Directory /var/www/html/SuiteCRM/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

ServerName localhost
DocumentRoot /var/www/html/SuiteCRM/public

Any help is greatly appreciated!

Hola, fijate de instalar la extension mysqli en tu dockerfile:

RUN docker-php-ext-install mysqli

Looks like I was just misinterpreting the error and it was actually to do with me misunderstanding how docker handles networking. After I changed all attempts at accessing localhost in my docker container to host.docker.internal I was able to access localhost services in the host system!

@jarodwr Complete answers to your questions about docker-izing SuiteCRM and the database, are here!