技術をかじる猫

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

Docker(17.12.0) Dockerfile からのイメージ作成

内容的には前回やった事を自動化する。

white-azalea.hatenablog.jp

だってこんなのイメージで持ち続けるって大変じゃね?
ってことで、スクリプトでイメージの作り方を指定するらしい。

XXXXXXXX$ cat Dockerfile 
FROM ubuntu

# Install requirements.
RUN apt-get update -y

# install ubuntu node
RUN apt-get install curl nodejs npm -y
RUN npm cache clean

# install n and nodejs stable
RUN npm install n -g
RUN n stable
RUN ln -sf /usr/local/bin/node /usr/bin/node

# remove ubuntu default node
RUN apt-get purge -y nodejs npm

ubuntu をベースに実行するコマンドを列挙しただけの簡易構成。

XXXXXXX$ docker build -t ubuntu-node .
Sending build context to Docker daemon  2.048kB
Step 1/8 : FROM ubuntu
 ---> 0458a4468cbc
Step 2/8 : RUN apt-get update -y
 ---> Running in 87ece63764c1
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [58.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [563 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
  中略
Removing intermediate container c06f58876486
 ---> 388c19df4ec2
Successfully built 388c19df4ec2
Successfully tagged ubuntu-node:latest

というログを吐いてビルド終了。
早速確認してみる。

XXXXXXX:nodeimg azalea$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
ubuntu-node         latest              388c19df4ec2        About a minute ago   562MB
wordpress           latest              ef4787e1820e        8 days ago           410MB
ubuntu              latest              0458a4468cbc        3 weeks ago          112MB
mysql               latest              f008d8ff927d        4 weeks ago          409MB
nginx               latest              3f8a4339aadd        7 weeks ago          108MB
hello-world         latest              f2a91732366c        2 months ago         1.85kB
XXXXXXX:nodeimg azalea$ 

無事 ubuntu-node イメージが出来上がった。

XXXXXXX$ docker run ubuntu-node node --version
v9.4.0

ひゃっはー