Issue connecting custom emr image to mysql on startup using docker-compose

Situation

I cloned a copy of openemr and put it on gh.
made changes to logos, in public/images/logos, made changes to branding options and appearance options in globals.inc/php, made some minor changes to some scss files, and added some custom user roles in /sites/default/documents/custom_menus/ and interface/main/tabs/menu/menus/

from there I cloned the openemr devops, and docker/7.0.3/Dockerfile I changed the source of the github pull to be the cloned copy I made of openemr. new image builds fine. I push that to dockerhub.

the issue is when I then try to docker-compose and using the image I have instead of openemr/openemr:7.0.3, it breaks and becomes unhealthy and doesnt work. If I change image to the openemr/openemr:7.0.3, it spins up just fine. I then tried changing mysqlconf.php $config = 0 (from 1), docker-compose now spins up and sends me to the installation wizard, and it connects to the database however cannot connect as user “openemr12345”.

my docker compose env vars are: for mysql: MYSQL_ROOT_PASSWORD: root,

for openemr: MYSQL_HOST: mysql, MYSQL_ROOT_PASS: , MYSQL_USER: openemr12345, MYSQL_PASS: openemr12345, OE_USER: openemr12345, OR_PASS: openemr12345

having root pass for mysqlrootpass in openemr as empty works, even tho its set to root ion the mysql.

OpenEMR Version
base image is 7.0.3

Browser:
I’m using: chrome

Operating System
I’m using: ubuntu vm

Search
Did you search the forum for similar questions? profusely

Logs
Did you check the logs? yup
Was there anything pertinent in them? Kinda more generic than I was hoping for tbh, issue is certainly a failure to connect mysql to the openemr image, and this is when I have the $config = 1 in sqlconfig.php
```


 thrown in /var/www/localhost/htdocs/openemr/auto_configure.php on line 43
 Couldn't set up. Any of these reasons could be what's wrong:
  - You didn't spin up a MySQL container or connect your OpenEMR container to a mysql instance
  - MySQL is still starting up and wasn't ready for connection yet
  - The Mysql credentials were incorrect
 mkdir: can't create directory '/tmp/php-file-cache': File exists
 PHP Fatal error:  Uncaught Exception: ERROR: unable to connect to database as root
  in /var/www/localhost/htdocs/openemr/auto_configure.php:43
 Stack trace:
#0 {main}

however when I have config = 0, I get to this point in the installation wizard and breaks:

I have tried a lot of iterations of changing these core values, in the installation wizard and otherwise. What am I missing? please help…

Okay, so I solved this one. But the solve is kind of weird cause it would indicate that the default images provided by the openemr/openemr:7.0.3 shouldn’t work with the default provided mysql/mariadb image. but it revolves aorund what the openemr host is. everywhere it is displayed as “localhost” and suggested it be left as that if both images are hosted on same machine. But this is wrong? maybe? as if you check the docker network, the adddress for the openemr image is like 172.something.something.3, and if you feed that in the openemr host it works and connects. Why does the standard image work but the lightly customized image (that doesnt touch sqlconf.php, autoconfigure.php, or the docker network configuratins) change that connection behavior?

Also this still only works when I do a manual installation using the gui with $config = 0 in sqlconf.php. Would love to get this working without the manual setup, but alas, haven’t gotten that working yet, even with the revelation of docker network openemr container ip address should be the openemr host…

Hi, Russel.

Whatever’s gone wrong here, the manual configuration is not how we’re getting out of it. Please paste your modified Dockerfile. I suspect that you haven’t modified 25-52 far enough.

Hi there Asher,

you bet, this is it:

```

FROM alpine:3.20
 
#Install dependencies and fix issue in apache
RUN apk --no-cache upgrade
RUN apk add --no-cache \
  apache2 apache2-ssl apache2-utils apache2-proxy git php83 php83-tokenizer php83-ctype php83-session php83-apache2 \
  php83-json php83-pdo php83-pdo_mysql php83-curl php83-ldap php83-openssl php83-iconv \
  php83-xml php83-xsl php83-gd php83-zip php83-soap php83-mbstring php83-zlib \
  php83-mysqli php83-sockets php83-xmlreader php83-redis php83-simplexml php83-xmlwriter php83-phar php83-fileinfo \
  php83-sodium php83-calendar php83-intl php83-opcache php83-pecl-apcu php83-fpm \
  perl mysql-client mariadb-connector-c tar curl imagemagick nodejs npm \
  certbot openssl openssl-dev dcron \
  rsync shadow ncurses
RUN sed -i 's/^Listen 80$/Listen 0.0.0.0:80/' /etc/apache2/httpd.conf
# Needed to ensure permissions work across shared volumes with openemr, nginx, and php-fpm dockers
RUN usermod -u 1000 apache
#BELOW LINE NEEDED TO SUPPORT PHP8 ON ALPINE 3.13+; SHOULD BE ABLE TO REMOVE THIS IN FUTURE ALPINE VERSIONS
RUN ln -sf /usr/bin/php83 /usr/bin/php
# Install composer for openemr package building
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
 
RUN apk add --no-cache openssh-client
 
ADD repo-key /
RUN chmod 600 /repo-key \
&& echo "IdentityFile /repo-key" >> /etc/ssh/ssh_config \
&& echo "StrictHostKeyChecking no">> /etc/ssh/ssh_config
 
RUN cat /etc/ssh/ssh_config
 
RUN apk add --no-cache git build-base \
&& git clone git@github.com:org/openemrclone.git --branch main --depth 1 \
&& mv openemrclone openemr \
&& cd openemr \
&& composer install --no-dev \
&& npm install --unsafe-perm \
&& npm run build \
&& cd ccdaservice \
&& npm install --unsafe-perm \
&& cd ../ \
&& composer global require phing/phing \
&& /root/.composer/vendor/bin/phing vendor-clean \
&& /root/.composer/vendor/bin/phing assets-clean \
&& composer global remove phing/phing \
&& composer dump-autoload --optimize --apcu \
&& composer clearcache \
&& npm cache clear --force \
&& rm -fr node_modules \
&& cd ../ \
&& mv openemr /var/www/localhost/htdocs/ \
&& chown -R apache:apache /var/www/localhost/htdocs/openemr/sites \
&& chmod -R 666 /var/www/localhost/htdocs/openemr/sites \
&& chown -R apache:apache /var/www/localhost/htdocs/openemr/ \
&& mkdir -p /etc/ssl/certs /etc/ssl/private \
&& apk del --no-cache git build-base \
&& sed -i 's/^ *CustomLog/#CustomLog/' /etc/apache2/httpd.conf \
&& sed -i 's/^ *ErrorLog/#ErrorLog/' /etc/apache2/httpd.conf \
&& sed -i 's/^ *CustomLog/#CustomLog/' /etc/apache2/conf.d/ssl.conf \
&& sed -i 's/^ *TransferLog/#TransferLog/' /etc/apache2/conf.d/ssl.conf
WORKDIR /var/www/localhost/htdocs/openemr
VOLUME [ "/etc/letsencrypt/", "/etc/ssl" ]
#configure apache & php properly
RUN echo "made it to here: 1"
ENV APACHE_LOG_DIR=/var/log/apache2
COPY php.ini /etc/php83/php.ini
COPY openemr.conf /etc/apache2/conf.d/
#add runner and auto_configure and prevent auto_configure from being run w/o being enabled
COPY openemr.sh ssl.sh xdebug.sh auto_configure.php /var/www/localhost/htdocs/openemr/
COPY utilities/unlock_admin.php utilities/unlock_admin.sh /root/
RUN chmod 755 openemr.sh ssl.sh xdebug.sh /root/unlock_admin.sh
RUN chmod 000 auto_configure.php /root/unlock_admin.php
#bring in pieces used for automatic upgrade process
COPY upgrade/docker-version \
  upgrade/fsupgrade-1.sh \
  upgrade/fsupgrade-2.sh \
  upgrade/fsupgrade-3.sh \
  upgrade/fsupgrade-4.sh \
  upgrade/fsupgrade-5.sh \
  upgrade/fsupgrade-6.sh \
  upgrade/fsupgrade-7.sh \
  /root/
RUN chmod 500 \
  /root/fsupgrade-1.sh \
  /root/fsupgrade-2.sh \
  /root/fsupgrade-3.sh \
  /root/fsupgrade-4.sh \
  /root/fsupgrade-5.sh \
  /root/fsupgrade-6.sh \
  /root/fsupgrade-7.sh
#fix issue with apache2 dying prematurely
RUN mkdir -p /run/apache2
#Copy dev tools library to root
COPY utilities/devtoolsLibrary.source /root/
#Ensure swarm/orchestration pieces are available if needed
RUN mkdir /swarm-pieces
RUN rsync --owner --group --perms --delete --recursive --links /etc/ssl /swarm-pieces/
RUN rsync --owner --group --perms --delete --recursive --links /var/www/localhost/htdocs/openemr/sites /swarm-pieces/
#go
RUN apk add --no-cache dos2unix \
&&  dos2unix /var/www/localhost/htdocs/openemr/*.sh
 
RUN rm -rf /tmp/php-file-cache
 
CMD [ "./openemr.sh" ]
 
EXPOSE 80 443

Some possibilities exist.

  • The 7.0.3 Dockerfile doesn’t work with the current state of the repo’s head which actually needs changes reflected in the 7.0.4 Dockerfile, and you need to either pull a 7.0.3-tagged release or you need to move to 7.0.4.
  • Something’s weird with your git setup? You could just use git clone <repo> <directory>, you don’t need the rename like you’re doing.
  • You’ve added things like the dos2unix call that make me really wonder what your local environment is like.

My advice:

  • Make a public clone of our repo, rename it something not-openemr, change nothing in the repo, pull the devops repo, go to the 7.0.4 Dockerfile, change only the single line 93, and see if you can’t build that image and use it in a local docker-compose.
  • If that succeeds, make a private clone of our repo, continue to change nothing in it, add your SSL for the git clone, and repeat the exercise.
  • If that succeeds, start patching your repo or adding capabilities to the Dockerfile.

Hey Asher,

Thanks for the time and feedback! We took your advice on updating to 7.0.4 and things are looking good. Still having issues with the auto load on startup and it only works when we use the set up wizard thingy, but thats okay for now.

lol yeah the dos to unix call was something I tried cause I use a windows machine and wondered if there was some conflict, but it also didnt hurt anything so left it.

Thanks again for taking the time to look and respond!

1 Like