技術をかじる猫

適当に気になった技術や言語、思ったこと考えた事など。

Docker(17.12.0) Dockerfile を使ってアプリケーションイメージを作成する

まずはデプロイするアプリケーションから。
これは Playframework のものを…

ってダメだお前…依存多すぎ DL 遅すぎ…。
今回試したいのは Play じゃないんだってば(汗

Dockerfile をまず作る。

$ vim Dockerfile
FROM ubuntu

# install python3
RUN apt-get update -y
RUN apt-get install python3 -y

# Create application dir
RUN mkdir /app
ADD index.html /app

# Start web server
WORKDIR /app

# Open port
EXPOSE 8000
CMD [ "python3", "-m", "http.server", "8000" ]

Python をさっさとインストールして、/app 配下で web サーバを 8000 ポートで立ち上げろという指示。
どーでもいいが、Ubuntupython は普通に 2.6 なんよね…Python3 インストールするとコマンドが python3 とかホントヤダ…

index.html はこんな感じでいいかね?

<html>
<body>
  <p>Simple message.</p>
</body>
</html>

という事でビルド

$ docker build -t example/python-web .
Sending build context to Docker daemon  3.072kB
Step 1/8 : FROM ubuntu
 ---> 0458a4468cbc
Step 2/8 : RUN apt-get update -y
 ---> Using cache
 ---> e804ebbf1b24
Step 3/8 : RUN apt-get install python3 -y
 ---> Running in 88714e60b80d
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  中略
Step 7/8 : EXPOSE 8000
 ---> Running in da3dff3d02ea
Removing intermediate container da3dff3d02ea
 ---> 5d96e9b282c6
Step 8/8 : CMD [ "python", "-m http.server", "8000" ]
 ---> Running in 02858ca42d76
Removing intermediate container 02858ca42d76
 ---> 538e92c4647b
Successfully built 538e92c4647b
Successfully tagged example/python-web:latest

そして起動

$ docker run -p 8080:8000 --name py-web example/python-web

OK 起動した

f:id:white-azalea:20180217230019p:plain