

This way will endure any container/volume deletion as opposed to manually granting the privileges. That way when mysql is run for the first time it will execute the file and grant the appropiate privileges. To solve the problem you can create a file with the following content GRANT ALL PRIVILEGES ON db_production.* TO mount it in the /docker-entrypoint-initdb.d folder. Setting the environment variable MYSQL_USER in the docker file just creates the user, but grants no privileges to it. It fails at the step rake db:create and when trying to run it manually via rails console I got the same error. How come Rails can't connect to it ? There are no detailed logs. So I don't understand much what exactly is happening, since I can successfully connect to MySQL through container's CLI and PhpMyAdmin.

#DOCKER PHPMYADMIN ACCESS TO MYSQL HOST INSTALL#
I had to add RUN apt-get install -y default-mysql-client to the Dockerfile in order to have MySQL working in the Rails container, otherwise it was not found, but on my other server I did not have to do this.I'm now trying to make it works on this server on Ubuntu 20.04.This configuration is working fine on another server on Ubuntu 22.04.RUN apt-get install -y default-mysql-clientĬMD
#DOCKER PHPMYADMIN ACCESS TO MYSQL HOST UPDATE#
RUN apt-get update & apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget RUN apt-get update & apt-get install -y nodejs yarn RUN echo "deb stable main" | tee /etc/apt//yarn.list RUN echo "deb stretch main" > /etc/apt/sources.list dockerfiles/production.dockerfileĬommand: bash -c "sleep 5 & bundle exec rails db:create db:migrate & bundle exec puma -C config/puma.rb" Mysql2::Error::ConnectionError: Access denied for user to database 'db_production'ĭockerfile. Context : Rails 6 app hosted in Docker, using docker-compose
