• Shauna Gordon's avatar
    6 - Configure The Database and Test Connection · 3aad6856
    Shauna Gordon authored
    Now, we need to make sure our database connection is working. One of the cool things about Docker is that the image maintainers can set up scripts that run the contents of folders under certain circumstances. One such use case is with importing a database upon container creation, with the docker-entrypoint-initdb.d folder. We'll do that to automate the filling out of a sample table for us.
    
    Next, we need to establish the connection. The big difference is in where we tell PHP where our database server is. In *AMPP and Vagrant setups, the database server typically lives on the same machine as the PHP process manager and server, but this isn't the case in a Docker cluster. The database gets its own service. So, instead of "localhost," we need to give it our container name. Once we do that, we can access our database like normal. With any luck, our page should now show us a list of lines that say "Hello, $name" (with the name filled in with data from our database, of course).
    3aad6856
data.sql 1.92 KB