LoginSignup
1
0

More than 5 years have passed since last update.

Windows 環境で Docker を使って LAMP (P は Perl)する

Last updated at Posted at 2019-06-04

背景

  • ありものを使ってお手軽に LAMP(erl)環境が作れないかを試した結果のまとめ

Docker for Windows をセットアップする

LAP(Linux/Apache/Perl) コンテナを作る

  • https://github.com/pclinger/docker-apache-perl
    • c:/www フォルダはあらかじめ作成しておく
    • フォルダマウント時に Docker から許可/認証(ひっそりと窓が出るので注意)をする必要がある
    • 前回うまくいっているのにエラーが出る場合は、Docker for Windows の Settings で Reset credentials をする
    • Port 80が既に使われていると言われたらぐぐって何とかする
    • 私の場合は BrancheCache が Port 80 を使っていたので一時的に止めた
  • 動作確認
hoge.cgi
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "Perl Programming";
exit;

M(MySQL) コンテナを作る

$ docker pull mysql
$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=mysql -d -p 3306:3306 mysql

コンテナに接続して IP アドレスを確認する
$ docker ps 
$ docker exec -it コンテナID bash
# cat /etc/hosts
名前がコンテナ ID の IP アドレスを控えておく

LAMP 全体の動作を確認する

mysql.cgi
#!/usr/bin/perl

use DBI;

my $dsn = "dbi:mysql:database=information_schema;host=[MySQL コンテナの IP アドレス];port=3306";

my $user = "root";
my $pass = "mysql";

my $dbh = DBI->connect( $dsn, $user, $pass, {
    AutoCommit => 1,
    PrintError => 0,
    RaiseError => 1,
    ShowErrorStatement => 1,
    AutoInactiveDestroy => 1
})|| die $DBI::errstr;

print "Content-type: text/html\n\n";

my $sth = $dbh->prepare("SELECT * FROM engines");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
    print "Found a row: engine = $ref->{'ENGINE'}, comment = $ref->{'COMMENT'}<br>";
}
$sth->finish();

$dbh->disconnect();

exit;

感想

  • ありものを使うことにすると細かいところで手作業が発生する
    • Dockerfile や Docker Compose を自分で書いて複数のコンテナを管理するなどしたほうが、長い目で見ると幸せな感じがしました (当たり前)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0