Posted: 18.09.2015
**Note! I have updated this post with Docker Toolbox and some other modifications. **
See the original Docker & MunkiReport post here.
I wanted to test MunkiReport and MySQL in non-production environment and didn’t want to install MySQL on my host machine. I’ve tested Docker couple of times before but never really “needed” it for Mac admin related tasks, except now. Here are few (not very verbose) notes about how MunkiReport test environment was built using Docker.
Requirements
Docker images @ Docker Hub
Launch Terminal and start default Docker Machine:
$ docker-machine start default
Set environment variables:
$ eval "$(docker-machine env default)"
Create data container db_data based on Ubuntu image:
docker run -d -v /var/lib/mysql --name db_data ubuntu
Run MySQL container db_app, connect it to the data container db_data & create a database for MunkiReport:
$ docker run -d --name db_app --volumes-from db_data -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=munkireport -e MYSQL_USER=admin -e MYSQL_PASSWORD=admin mysql
Run MunkiReport mr container and connect it to db_app container. Change environment variables (if needed):
$ docker run -d -p 80:80 --name mr --link db_app:mysql -e DB_NAME=munkireport -e DB_USER=admin -e DB_PASS=admin -e DB_SERVER=db_app -e MR_SITENAME="Local tests" hunty1/munkireport-docker
Check that the both app containers are running and the data container is visible:
$ docker ps -a
Output example:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9fa44a71498 hunty1/munkireport-docker "/start.sh" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp, 443/tcp mr
8459a79a15ab mysql "/entrypoint.sh mysql" 18 seconds ago Up 17 seconds 0.0.0.0:3306->3306/tcp db_app
b9ec4a17adb8 ubuntu "/bin/bash" 26 seconds ago Exited (0) 25 seconds ago db_data
Get Docker machine IP address:
$ docker-machine ip default
This IP address will be used in the rest of the examples.
192.168.99.100
Go to http://192.168.99.100 and login with these credentials:
Username: root
Password: root
If everything went ok, you should see MunkiReport GUI with zero machines.
Note! You need Munki and MunkiReport installed on your host computer for this part.
Change MunkiReport BaseUrl
on the host computer (notice the trailing slash!):
$ sudo defaults write /Library/Preferences/MunkiReport.plist BaseUrl http://$(docker-machine ip default)/
Run managedsoftwareupdate:
$ sudo /usr/local/munki/managedsoftwareupdate
Refresh MunkiReport web GUI and check your host computer info.
It’s nice to have MunkiReport up and running but it’s quite useless if there’s no data to view. Run mysqldump on your production server and copy the MySQL database file to your Desktop:
$ cp path/to/my-munkireport-db.sql ~/Desktop/
Run separate MySQL client container and destroy it after database import. Replace my-munkireport-db.sql
with your db file name:
$ docker run -it --rm mysql --link=db_app:mysql -v ~/Desktop:/tmp/ sh -c 'exec mysql -h192.168.99.100 -P3306 -uroot -proot munkireport < /tmp/my-munkireport-db.sql'
You can ignore the warning message because we’re only testing:
Warning: Using a password on the command line interface can be insecure.
Connect to the database using Sequel Pro:
Or connect directly to the MySQL database with command line client:
docker exec -it db_app sh -c 'exec mysql -h192.168.99.100 -P3306 -uroot -proot munkireport'
Copy the munkireport
folder from MunkiReport container to your Desktop:
$ docker cp mr:/www/munkireport/ ~/Desktop/
Stop & delete current MunkiReport container:
$ docker stop mr
$ docker rm -f mr
Run MunkiReport container again and mount host volume ~/Desktop/munkireport
as a data volume. Change environment variables once again (if needed):
$ docker run -d -p 80:80 --name mr --link db_app:mysql -v ~/Desktop/munkireport:/www/munkireport -e DB_NAME=munkireport -e DB_USER=admin -e DB_PASS=admin -e DB_SERVER=db_app -e MR_SITENAME="Local tests" hunty1/munkireport-docker
Edit files in ~/Desktop/munkireport
folder:
Refresh MunkiReport web GUI and login again: http://192.168.99.100/
Stop all containers:
$ docker stop $(docker ps -aq)
Delete all Docker containers:
$ docker rm -f $(docker ps -aq)
Shutdown default Docker Machine:
$ docker-machine stop default
Change MunkiReport BaseUrl
back to the original one:
$ sudo defaults write /Library/Preferences/MunkiReport.plist BaseUrl http://your_munki_repo/
Check out Calum Hunter’s GitHub page for more info if you want to tinker with MunkiReport container settings.