13 may
Monday! Fresh week without any mistakes in yet, right? Ha.
docker mariaDB data
I struggled this morning to get the data I managed to dump out of the webapps_hours
database on Friday into the docker container, but I did it!
First, dumping the SQL:
- Doesn’t matter where you are in the server, this command connects to the MySQL database and dumps the table you’re asking for:
mysqldump -u username -p --databases databasename > filename.sql
- This ended up in my home drive on the server, so I FTP’d it to my local machine, straight into the directory with the
docker-compose
file in it -
To make that file available to the docker container, I had to mount a new volume in
docker-compose
undermariadb
(that second volume is the new one):volumes: - mariadb:/var/lib/mysql - .:/mnt/mydata
Then, importing the SQL:
- make sure docker is up
docker-compose up -d
- getchyoself in interactive shell mode
docker exec -it [container-name_mariadb_1] bash
- traverse to your mounted volume
cd /mnt/mydata
- import that database, yo
mysql -u username -p < filename.sql
I struggled forever because I kept trying to put this data into the database the docker container created, testdb
. BUT the dump file is set up so it creates a new database. I only figure that out after trying forever to use mysql -u username -p testdb < filename.sql
and nothing happening, so I finally opened the SQL file. The CREATE statement was right at the top, so, my bad.
To enter the database, mysql -u username -p webapps_hours
. Then show tables;
to verify there’s stuff in there. Boom!
helpful articles
- This might’ve been overkill, but I learned a ton: Servers for Hackers: Docker Volumes
16 may
Tuesday was lots of treehouse tutorials, which helped reinforce my understanding of PDO, connecting to database, querying database, and retrieving results via PHP.
Yesterday was abysmal. We’re trying to ramp up the speed on migrating to PHP 7, so I struggled pretty much all day yesterday to get my docker containers to connect to a database. I created at least 7 different images/containers, and none of them worked. I left here pretty dejected.
Today!
PHP <-> MySQL connection success!
It took me a few more hours to work through some things this morning, but I have officially connected successfully to the database and retrieved results/spit them out in localhost.
This article is what (somehow) did the trick: Create your first PHP/MySQL application in Docker.
I think my issues had to do with exposing ports and container names? Something I didn’t realize is that instead of using “localhost” in the PDO connection statement, you need to use your database container name. Also, in all of my failed attempts, I didn’t have an EXPOSE
statement in my Dockerfile because I was using ports statements, but that’s another change that might’ve made a difference. I don’t want to test out that theory right now because it’s working, and I’m good with that.
Next up: connecting the alerts
app/API, superGlobalPHP
API, and docker and seeing what blows up. If everything connects and seems to be doing well, I’ll set up phan in the same container to run a migration analysis.