NAME
Test::Docker::MySQL is a module to launch MySQL in docker containers.
SYNOPSIS
# You have to setup docker manually before you use this (see SETUP section)
use
Test::Docker::MySQL;
my
$dm_guard
= Test::Docker::MySQL->new;
my
$port_1
=
$dm_guard
->get_port;
# get a mysql container port
my
$port_2
=
$dm_guard
->get_port;
# get another mysql container port
my
$dsn_1
=
"dbi:mysql:database=mysql;host=127.0.0.1;port=$port_1"
;
my
$dbh_1
= DBI->
connect
(
$dsn
,
'root'
,
''
, {
RaiseError
=> 1 });
my
$dsn_2
=
"dbi:mysql:database=mysql;host=127.0.0.1;port=$port_2"
;
my
$dbh_2
= DBI->
connect
(
$dsn
,
'root'
,
''
, {
RaiseError
=> 1 });
undef
$dm_guard
;
# dispatch `docker kill $container` command
DESCRIPTION
Test::Docker::MySQL is a module to launch MySQL in docker containers.
METHODS
new
All parameters are optional.
tag
-
The tag to launch via Docker. Default value is
punytan/p5-test-docker-mysql
. ports
-
Specify port range by
ports
. Default value is[ 55500 .. 55555 ]
,
get_port
Returns allocated port.
SETUP
OSX
- Install boot2docker and docker
-
You can find the binary at https://github.com/boot2docker/osx-installer/releases.
- Initialize boot2docker
-
$ boot2docker download && boot2docker init && boot2docker up
- Configure port forwarding
-
$ boot2docker down
$
for
i in {55500..55555};
do
VBoxManage modifyvm
"boot2docker-vm"
--natpf1
"tcp-port$i,tcp,,$i,,$i"
;
VBoxManage modifyvm
"boot2docker-vm"
--natpf1
"udp-port$i,udp,,$i,,$i"
;
done
$ boot2docker up
- Pull docker images for this module
-
$ docker pull punytan/p5-test-docker-mysql
CHEATSHEET
Clean up containers
$ docker
kill
$(docker ps -a -
q)
$ docker rm $(docker ps -a -q)
DEBUGGING
Set DEBUG_TEST_DOCKER_MYSQL
as true to get verbose log generated by this module.
AUTHOR
punytan <punytan@gmail.com>
COPYRIGHT
Copyright 2014- punytan
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.