Setting up a MySQL database server, in Docker, to serve multiple applications There is one user ID per database, and each user ID only has access rights for its database. Once the database is running you can use SQL commands (or PHPMyAdmin) to create additional databases and user ID's. Each application will therefore only have access to its own data, and not to the data of other applications.Ĭonfiguring MySQL to support multiple databases and multiple user ID's is not unique to a Docker deployment.Ĭonfiguring the MySQL Docker container to support multiple databases and multiple user ID's starts with the configuration of a single database and single user ID. To maintain separation between the databases for each application, we define separate user ID's with separate access rights. What I chose was to work out how to reconfigure a Docker-based MySQL instance to support multiple user ID's and multiple databases. These features are hold-overs from the old days. As a result MySQL is quite capable of storing multiple databases in each server instance, along with multiple user ID's. In the old days we'd configure The Database Server (or servers), storing all data from a long list of applications. But it seemed to me excess overhead to follow that practice, especially since MySQL can easily support multiple databases per server. Using MySQL in the default fashion would result in three containers. Following the best practice that would mean three separate MySQL container instances. The case I faced which inspired this tutorial is that I have three websites, two using Drupal, the third using Wordpress, to deploy to a single VPS. Those environment variables support creating one user ID and one database. The default way to configure the MySQL Docker container is with environment variables. That means five (or more) containers for the applications, but what about the database server? Do you host five database server containers, each holding a single database? Or do you host a single database server container, holding five databases? QUICK-FIX: For some reason phpmyadmin doesn't add the port to the request: I had to set the following in the file /etc/phpmyadmin/: $cfg = "" after the port directive was set of course.Suppose you have five applications to host on a server, each with a separate database? Theoretically the best practice is for each Docker container to serve a single well defined purpose. I have no idea what i have to do, I'm overly frustrated, and if you ask, I basically put random lines from the internet to make my bash script and my dockerfile. " Cannot log in to the MySQL server", " mysqli_real_connect(): (HY000/2002): Permission denied", " Connection for controluser as defined in your configuration failed.", " mysqli_real_connect(): (HY000/2002): Permission denied" I can access apache2 through localhost:80 and I'm pretty sure mysql is up because my queries worked.īut logging in to localhost/phpmyadmin with "admin:admin" just won't work: ![]() I run my container through docker build -t whatever. Mysql -u root -password= -e "CREATE DATABASE PROJECT_MANAGEMENT "Īnd this is the content of my start.sh: #!/bin/bash Mysql -u root -password= -e "GRANT ALL PRIVILEGES ON *.* TO -u root -password= -e "FLUSH PRIVILEGES " Mysql -u root -password= -e "CREATE USER IDENTIFIED BY 'admin' " Mysql -u root -password= < /usr/share/phpmyadmin/sql/create_tables.sql ![]() ![]() # I'm creating the phpmyadmin database here This is the content of my init.sh: #!/bin/bash RUN cp /etc/phpmyadmin/nf /etc/apache2/conf-available/nf config-db.php /etc/phpmyadmin/config-db.php # I've set the dbuser to 'admin' dbpass to 'admin' hereĬOPY. RUN DEBIAN_FRONTEND=noninteractive apt -y install apache2 php libapache2-mod-php mysql-server php-mysql phpmyadmin This is the content of my dockerfile: FROM ubuntu:20.04 I'm trying to have one docker container with: ubuntu 20.04, on top of which I add apache, php, mysql and phpmyadmin (all on the same container)
0 Comments
Leave a Reply. |