7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sendmail (MTA)コンテナを作る

Last updated at Posted at 2016-01-20

MTAのコンテナ化について

コンテナ化したいサービスの1つがMTAだと思います。
MTAはその性質上、デーモン(サービス)として動作する物が殆どです。
これはコンテナの「フォアグラウンドで目的のプログラムを動作させる」という概念に反します。
時代の流れでpostfixといきたかったのですが難しく、今回はsendmailをコンテナ化します。

前提条件

作業端末

docker実行環境が整っていること。

Dockerのバージョン

作業端末でDockerが動作していれば、全て端末上でハンズオンが完了します。
動作していない場合、第3章のコンテナ作成部分を今回起動したコンテナインスタンス上で行うことも可能です。

以下のバージョンで動作確認済

  • Docker version 1.9.1
コマンド
docker --version
結果(例)
      Docker version 1.9.1, build a34a1d5/1.9.1
  1. コンテナの構築
    ===========

1.1 環境変数の設定

sendmailのコンテナを作成します。
今回はCentOS6をベースにsendmailのコンテナを作成します。
まずは作成するコンテナのレポジトリ名を定義してディレクトリを作成します。

コマンド
ECR_REPOSITORY=sendmail
mkdir ${ECR_REPOSITORY}
結果
      返り値なし

1.2. xinetd用設定ファイルの作成

xinetdにsmtp(tcp/25)をlistenさせるためのファイルを作成します。

コマンド
cat << EOF > ${ECR_REPOSITORY}/smtp
service smtp
{
        disable = no
        socket_type = stream
        wait = no
        user = root
        server = /usr/sbin/sendmail
        server_args = -bs
}
EOF
結果
      返り値なし

1.3. Dockerfile ファイルの作成

コマンド
cat << EOF > ${ECR_REPOSITORY}/Dockerfile
FROM centos:6
RUN yum -y install sendmail xinetd
RUN /bin/rm -f /etc/xinetd.d/*
ADD ${ECR_REPOSITORY}/smtp /etc/xinetd.d/smtp
CMD /usr/sbin/xinetd -dontfork
EOF
結果
      返り値なし

1.4. コンテナイメージのビルド

コマンド
docker build -t ${ECR_REPOSITORY} ${ECR_REPOSITORY}
結果(例)
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM centos:6
 ---> 1a895dd3954a
Step 2 : RUN yum -y install sendmail xinetd
 ---> Running in a919f56f3a24
Loaded plugins: fastestmirror
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package sendmail.x86_64 0:8.14.4-9.el6 will be installed
--> Processing Dependency: procmail for package: sendmail-8.14.4-9.el6.x86_64
--> Processing Dependency: initscripts for package: sendmail-8.14.4-9.el6.x86_64
--> Processing Dependency: /usr/sbin/saslauthd for package: sendmail-8.14.4-9.el6.x86_64
--> Processing Dependency: libwrap.so.0()(64bit) for package: sendmail-8.14.4-9.el6.x86_64
--> Processing Dependency: libhesiod.so.0()(64bit) for package: sendmail-8.14.4-9.el6.x86_64
---> Package xinetd.x86_64 2:2.3.14-39.el6_4 will be installed
--> Running transaction check
---> Package cyrus-sasl.x86_64 0:2.1.23-15.el6_6.2 will be installed
--> Processing Dependency: /sbin/nologin for package: cyrus-sasl-2.1.23-15.el6_6.2.x86_64
---> Package hesiod.x86_64 0:3.1.0-19.el6 will be installed
---> Package initscripts.x86_64 0:9.03.49-1.el6.centos.3 will be installed
--> Processing Dependency: upstart >= 0.6.5-11 for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: udev >= 125-1 for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: sysvinit-tools >= 2.87-6 for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: module-init-tools >= 3.9-25 for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: mingetty for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: /sbin/pidof for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: /sbin/ip for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: /sbin/fuser for package: initscripts-9.03.49-1.el6.centos.3.x86_64
--> Processing Dependency: /sbin/arping for package: initscripts-9.03.49-1.el6.centos.3.x86_64
---> Package procmail.x86_64 0:3.22-25.1.el6_5.1 will be installed
---> Package tcp_wrappers-libs.x86_64 0:7.6-57.el6 will be installed
--> Running transaction check
---> Package iproute.x86_64 0:2.6.32-45.el6 will be installed
--> Processing Dependency: iptables >= 1.4.5 for package: iproute-2.6.32-45.el6.x86_64
--> Processing Dependency: libxtables.so.4()(64bit) for package: iproute-2.6.32-45.el6.x86_64
---> Package iputils.x86_64 0:20071127-20.el6 will be installed
---> Package mingetty.x86_64 0:1.08-5.el6 will be installed
---> Package module-init-tools.x86_64 0:3.9-25.el6 will be installed
---> Package psmisc.x86_64 0:22.6-19.el6_5 will be installed
---> Package sysvinit-tools.x86_64 0:2.87-6.dsf.el6 will be installed
---> Package udev.x86_64 0:147-2.63.el6_7.1 will be installed
--> Processing Dependency: hwdata for package: udev-147-2.63.el6_7.1.x86_64
---> Package upstart.x86_64 0:0.6.5-13.el6_5.3 will be installed
---> Package util-linux-ng.x86_64 0:2.17.2-12.18.el6 will be installed
--> Running transaction check
---> Package hwdata.noarch 0:0.233-14.1.el6 will be installed
---> Package iptables.x86_64 0:1.4.7-16.el6 will be installed
--> Processing Dependency: policycoreutils for package: iptables-1.4.7-16.el6.x86_64
--> Running transaction check
---> Package policycoreutils.x86_64 0:2.0.83-24.el6 will be installed
--> Processing Dependency: libsemanage.so.1(LIBSEMANAGE_1.0)(64bit) for package: policycoreutils-2.0.83-24.el6.x86_64
--> Processing Dependency: libsemanage.so.1()(64bit) for package: policycoreutils-2.0.83-24.el6.x86_64
--> Running transaction check
---> Package libsemanage.x86_64 0:2.0.43-5.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package               Arch       Version                     Repository   Size
================================================================================
Installing:
 sendmail              x86_64     8.14.4-9.el6                base        716 k
 xinetd                x86_64     2:2.3.14-39.el6_4           base        121 k
Installing for dependencies:
 cyrus-sasl            x86_64     2.1.23-15.el6_6.2           base         78 k
 hesiod                x86_64     3.1.0-19.el6                base         20 k
 hwdata                noarch     0.233-14.1.el6              base        1.3 M
 initscripts           x86_64     9.03.49-1.el6.centos.3      updates     945 k
 iproute               x86_64     2.6.32-45.el6               base        367 k
 iptables              x86_64     1.4.7-16.el6                base        254 k
 iputils               x86_64     20071127-20.el6             base        120 k
 libsemanage           x86_64     2.0.43-5.1.el6              base        104 k
 mingetty              x86_64     1.08-5.el6                  base         21 k
 module-init-tools     x86_64     3.9-25.el6                  base        466 k
 policycoreutils       x86_64     2.0.83-24.el6               base        651 k
 procmail              x86_64     3.22-25.1.el6_5.1           base        162 k
 psmisc                x86_64     22.6-19.el6_5               base         81 k
 sysvinit-tools        x86_64     2.87-6.dsf.el6              base         60 k
 tcp_wrappers-libs     x86_64     7.6-57.el6                  base         62 k
 udev                  x86_64     147-2.63.el6_7.1            updates     355 k
 upstart               x86_64     0.6.5-13.el6_5.3            base        177 k
 util-linux-ng         x86_64     2.17.2-12.18.el6            base        1.6 M

Transaction Summary
================================================================================
Install      20 Package(s)

Total download size: 7.5 M
Installed size: 28 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           5.0 MB/s | 7.5 MB     00:01
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-7.el6.centos.12.3.x86_64 (installed)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : module-init-tools-3.9-25.el6.x86_64                         1/20
  Installing : sysvinit-tools-2.87-6.dsf.el6.x86_64                        2/20
  Installing : tcp_wrappers-libs-7.6-57.el6.x86_64                         3/20
  Installing : hwdata-0.233-14.1.el6.noarch                                4/20
  Installing : psmisc-22.6-19.el6_5.x86_64                                 5/20
  Installing : mingetty-1.08-5.el6.x86_64                                  6/20
  Installing : procmail-3.22-25.1.el6_5.1.x86_64                           7/20
  Installing : libsemanage-2.0.43-5.1.el6.x86_64                           8/20
  Installing : upstart-0.6.5-13.el6_5.3.x86_64                             9/20
  Installing : policycoreutils-2.0.83-24.el6.x86_64                       10/20
  Installing : iptables-1.4.7-16.el6.x86_64                               11/20
  Installing : iproute-2.6.32-45.el6.x86_64                               12/20
  Installing : iputils-20071127-20.el6.x86_64                             13/20
  Installing : util-linux-ng-2.17.2-12.18.el6.x86_64                      14/20
install-info: No such file or directory for /usr/share/info/ipc.info
  Installing : initscripts-9.03.49-1.el6.centos.3.x86_64                  15/20
  Installing : udev-147-2.63.el6_7.1.x86_64                               16/20
  Installing : cyrus-sasl-2.1.23-15.el6_6.2.x86_64                        17/20
  Installing : hesiod-3.1.0-19.el6.x86_64                                 18/20
  Installing : sendmail-8.14.4-9.el6.x86_64                               19/20
  Installing : 2:xinetd-2.3.14-39.el6_4.x86_64                            20/20
  Verifying  : hesiod-3.1.0-19.el6.x86_64                                  1/20
  Verifying  : tcp_wrappers-libs-7.6-57.el6.x86_64                         2/20
  Verifying  : upstart-0.6.5-13.el6_5.3.x86_64                             3/20
  Verifying  : initscripts-9.03.49-1.el6.centos.3.x86_64                   4/20
  Verifying  : sysvinit-tools-2.87-6.dsf.el6.x86_64                        5/20
  Verifying  : sendmail-8.14.4-9.el6.x86_64                                6/20
  Verifying  : util-linux-ng-2.17.2-12.18.el6.x86_64                       7/20
  Verifying  : hwdata-0.233-14.1.el6.noarch                                8/20
  Verifying  : 2:xinetd-2.3.14-39.el6_4.x86_64                             9/20
  Verifying  : libsemanage-2.0.43-5.1.el6.x86_64                          10/20
  Verifying  : policycoreutils-2.0.83-24.el6.x86_64                       11/20
  Verifying  : iptables-1.4.7-16.el6.x86_64                               12/20
  Verifying  : procmail-3.22-25.1.el6_5.1.x86_64                          13/20
  Verifying  : udev-147-2.63.el6_7.1.x86_64                               14/20
  Verifying  : iputils-20071127-20.el6.x86_64                             15/20
  Verifying  : mingetty-1.08-5.el6.x86_64                                 16/20
  Verifying  : cyrus-sasl-2.1.23-15.el6_6.2.x86_64                        17/20
  Verifying  : module-init-tools-3.9-25.el6.x86_64                        18/20
  Verifying  : psmisc-22.6-19.el6_5.x86_64                                19/20
  Verifying  : iproute-2.6.32-45.el6.x86_64                               20/20

Installed:
  sendmail.x86_64 0:8.14.4-9.el6         xinetd.x86_64 2:2.3.14-39.el6_4

Dependency Installed:
  cyrus-sasl.x86_64 0:2.1.23-15.el6_6.2
  hesiod.x86_64 0:3.1.0-19.el6
  hwdata.noarch 0:0.233-14.1.el6
  initscripts.x86_64 0:9.03.49-1.el6.centos.3
  iproute.x86_64 0:2.6.32-45.el6
  iptables.x86_64 0:1.4.7-16.el6
  iputils.x86_64 0:20071127-20.el6
  libsemanage.x86_64 0:2.0.43-5.1.el6
  mingetty.x86_64 0:1.08-5.el6
  module-init-tools.x86_64 0:3.9-25.el6
  policycoreutils.x86_64 0:2.0.83-24.el6
  procmail.x86_64 0:3.22-25.1.el6_5.1
  psmisc.x86_64 0:22.6-19.el6_5
  sysvinit-tools.x86_64 0:2.87-6.dsf.el6
  tcp_wrappers-libs.x86_64 0:7.6-57.el6
  udev.x86_64 0:147-2.63.el6_7.1
  upstart.x86_64 0:0.6.5-13.el6_5.3
  util-linux-ng.x86_64 0:2.17.2-12.18.el6

Complete!
 ---> d3c8ed5599ff
Removing intermediate container a919f56f3a24
Step 3 : RUN /bin/rm -f /etc/xinetd.d/*
 ---> Running in fd288eeb9b6b
 ---> 7b68f708ebd6
Removing intermediate container fd288eeb9b6b
Step 4 : ADD smtp /etc/xinetd.d/smtp
 ---> c1a36e423042
Removing intermediate container 19b919f08c8a
Step 5 : CMD /usr/sbin/xinetd -dontfork
 ---> Running in 028b5d125f51
 ---> b4df9633ce73
Removing intermediate container 028b5d125f51
Successfully built b4df9633ce73

最後の行に Successfully built と出ていれば成功です。

  1. 動作試験
    ===========

2.1. コンテナの起動

コマンド
docker run -d -p 25:25 ${ECR_REPOSITORY}
結果(例)
0c942716bfb23d4a0ec1ef5c2d47466ad3dc15af9d2d1b23001a2c875428a648

2.2. 動作しているか確認する

コマンド
telnet localhost 25

現状、hostname問題のため応答が来るまで数十秒かかります。

結果(例)
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 0c942716bfb2 ESMTP Sendmail 8.14.4/8.14.4/Submit; Wed, 20 Jan 2016 15:23:28 GMT

220プロンプトでsendmailの応答が来れば動作成功です。

まとめ

とりあえず動作させることは成功しています。
設定をどのように持ち込むかは今後の課題とします。
(ハードコーディングでもいいかもしれない)
なおこれはAWS ECR+ECSハンズオンの前座です。今後改訂します…

7
7
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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?