This post was originally published on Siv Scripts
Being a Software Engineer isn't just about being effective in a specific programming language, i...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for the article. While trying to run through the above I ran into this error
ERROR: In file './docker-compose.yml', service must be a mapping, not a NoneType.which I solved by updating docker-compose.yml to this
The indentation matters and this finally got it working. Hope this helps anyone else trying to use this.
Thanks for the heads up!
Didn't realize the indentation got messed up as I copied this over. It has been corrected.
I'm just getting in to Docker so I'm actually glad it had that issue so I'm now aware that I have to get the indentation correct. :)
When working with the database from the application, I get the following:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:6 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 6
Connection code:
<?php
$servername = "localhost:9906";
$username = "devuser";
$password = "devpass";
$dbname = "test_db";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Fatal error: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
printf("Fatal error: %s\n", mysqli_connect_error());
exit();
}
?>
With the help of mysqlworkbench i can connect and work with the database!
Tell me where I went wrong and why it doesn't work?
Thanks, Aly. I have a question: if the container is restarted, are the MySQL databases lost? In other words, is there persistence in the database?
The setup I describe above stores data inside of the container. This data is lost when the container is deleted (
docker-compose down)You could mount a volume so the data is persisted on your local machine.
Looking at hub.docker.com/_/mysql/ (search for Where to Store Data), we can update the
docker-compose.ymlwith another volume mount as follows:Now data will persist in the
./sqldirectory.Thank you very much!