あくまで自分向けのメモだからどこか間違ってるかも
とりあえずまずは動けばいいやで
[bash]
mkdir dockertest
cd dockertest
[/bash]
で意味もあまりなけどディレクトリ入ってvimでDockerfileを作成
FROM base/archlinux RUN pacman -Syy --noconfirm RUN pacman -S --noconfirm nginx EXPOSE 80 CMD ["/bin/nginx", "-g", "daemon off;"]
nginxの立ち上げ方、本当にこれでいいのかな…
でこれをdocker buildでイメージ作成
[bash]
docker build -t mattyan/nginx .
[/bash]
やってることとしては、最初にpacmanのリポジトリと同期とって(アップデートはしてない)nginxのインストール。
でポート80を使用するように指定してイメージが呼ばれた時にnginxをフォアグラウンドモードで起動。
実行ログ
Sending build context to Docker daemon 2.048 kB Sending build context to Docker daemon Step 0 : FROM base/archlinux ---> dce0559daa1b Step 1 : RUN pacman -Syy --noconfirm ---> Running in ab83051b78c9 :: Synchronizing package databases... downloading core.db... downloading extra.db... downloading community.db... ---> f2579d2201b9 Removing intermediate container ab83051b78c9 Step 2 : RUN pacman -S --noconfirm nginx ---> Running in 44538fe31a22 resolving dependencies... looking for inter-conflicts... Packages (1): nginx-1.8.0-1 Total Download Size: 0.34 MiB Total Installed Size: 0.98 MiB :: Proceed with installation? [Y/n] :: Retrieving packages ... downloading nginx-1.8.0-1-x86_64.pkg.tar.xz... downloading nginx-1.8.0-1-x86_64.pkg.tar.xz... downloading nginx-1.8.0-1-x86_64.pkg.tar.xz... downloading nginx-1.8.0-1-x86_64.pkg.tar.xz... downloading nginx-1.8.0-1-x86_64.pkg.tar.xz... checking keyring... checking package integrity... loading package files... checking for file conflicts... checking available disk space... installing nginx... ---> fa7dd7429c1a Removing intermediate container 44538fe31a22 Step 3 : EXPOSE 80 ---> Running in c610d738ea89 ---> 8cb66de7206f Removing intermediate container c610d738ea89 Step 4 : CMD /bin/nginx -g daemon off; ---> Running in 12fece796ff4 ---> b5f07f3af17d Removing intermediate container 12fece796ff4 Successfully built b5f07f3af17d
で、イメージができたら
[bash]
docker run -i -t -d -p 80:80 mattyan/nginx
[/bash]
で実行。
-p 80:80
を忘れると外からコンテナに接続できないのに注意。
[bash]
docker ps
[/bash]
で起動中のコンテナを見ると
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a8e470239bab mattyan/nginx:latest "/bin/nginx -g 'daem 6 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp pensive_payne
とコンテナが動いてるのがわかる。
この状態でホストから
[bash]
curl localhost
[/bash]
すると
[html]
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[/html]
と返ってくるので、どうやら無事に動いたようだ。
Windows(ホストのArchの更にホスト)からIEでアクセス。
さぁ遊ぶ準備ができたぞ。