インフラ準備
環境について
まずは、ローカルでもクラウドでもいいので、
自分の開発環境を用意します。
僕は従量課金を気にしたくないので、自宅にPCを構えています。
昔、好き放題使いまくって痛い目みました。。。
今は自宅PCでごりごり作る、GitHubにプッシュ、クラウド(AWS)にデプロイ、の流れで使い分けをしています。
準備したもの
- Ubuntu
- Docker
- VSCode
「何のOSにしようか。。。」とか迷うこともあるかと思いますが、なんでもいいです。そこは時間かけるところじゃありません。
自分の資金や知識と要相談ですね。
"Node.js" さえ用意できればいいんです。
僕は高価なものが揃えられなかったので、デスクトップPCにLinuxの無料ディストリビューションである "Ubuntu" をインストールして使うことにしました。
Ubuntuの入手はこちら。
インストールは、isoイメージをCDやUSBに書き込んで、ブートするだけ。
あとは画面の指示に従ってれば入ります。
わからない方は、「ubuntu インストール」でググりましょう。
環境構築
下準備
開発に使うユーザーは、なんでもできる管理者ユーザー "root" を使います。
root ユーザーでログインするために、パスワードを変更します。
rascal@RascalRoom:~$ sudo passwd root [sudo] rascal のパスワード: 新しい UNIX パスワードを入力してください: 新しい UNIX パスワードを再入力してください: passwd: パスワードは正しく更新されました
sudo は root権限を取得できるコマンドです。
初めにログインユーザー(僕の環境では "rascal")のパスワードが聞かれます。
次に root のパスワードを登録します。
※悪意のある人にパスワードが流出すると危険です。
クラウド等のパブリック環境ではおすすめしません。
root ユーザーへログインします。
rascal@RascalRoom:~$ su -
パスワード:
root@RascalRoom:~#
これでよし。
Docker
コンテナと呼ばれるOSレベルの仮想化環境を提供するオープンソースソフトウェアである[3]。VMware製品などの完全仮想化を行うハイパーバイザ型製品と比べて、ディスク使用量は少なく、仮想環境 (インスタンス) 作成や起動は速く、性能劣化がほとんどないという利点を持つ。
もう主流ですね。
WindowsでもMacでもどこでも動くコンテナ技術は、今どきのエンジニアは必須でしょうね。中でもデファクトスタンダードというか、これしか聞かないといっても過言ではないのが、 "Docker(ドッカー)" です。
余談ですが、最近はWindowsでも、"WSL" が導入されてLinuxライクな環境を楽しめるようになってきましたね。
今後、気が向いたら使ってみます。。。
では、インストールしていきましょう。
公式手順はこちら。
以下、公式手順を載せます。
導入手順
① aptパッケージインデックスを更新します
rascal@RascalRoom:~# apt-get update
② HTTPS経由でaptのリポジトリを使用できるようにする
rascal@RascalRoom:~# apt-get install \n apt-transport-https \n ca-certificates \n curl \n gnupg-agent \n software-properties-common
③ Dockerの公式GPGキーを追加します
rascal@RascalRoom:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
フィンガープリントの確認をしておきましょう。
root@RascalRoom:~# apt-key fingerprint 0EBFCD88 pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ 不明 ] Docker Release (CE deb) <docker@docker.com> sub rsa4096 2017-02-22 [S]
「9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88」であれば、オッケーです。
④ 安定版リポジトリを設定します
rascal@RascalRoom:~# add-apt-repository \n "deb [arch=amd64] https://download.docker.com/linux/ubuntu \n $(lsb_release -cs) \n stable"
⑤ DOCKER CEをインストール
rascal@RascalRoom:~# apt-get update rascal@RascalRoom:~# apt-get install docker-ce
Dockerのインストールは完了です。
使い方
① Dockerfile を作る
rascal@RascalRoom:~# mkdir app1 rascal@RascalRoom:~# cd app1 rascal@RascalRoom:~/app1# vi Dockerfile
参考
FROM node:latest WORKDIR /work RUN apt-get update RUN apt-get install -y vim net-tools ssh mongodb RUN npm -g install forever RUN npm -g install sails RUN echo "export LANG=C.UTF-8" >> /etc/profile.d/lang.sh RUN echo "export LANGUAGE=en_US:" >> /etc/profile.d/lang.sh RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config RUN echo "root:{root password}" | chpasswd -m RUN echo 2 | sails new app --fast WORKDIR /work/app RUN npm install RUN npm install sails-mongo --save CMD ["bash"]
FROM
> Dockerイメージを取得します。今回は "node" イメージの "latest(最新版)" を使います。
WORKDIR
> カレントディレクトリの移動と、もし移動先のディレクトリがない場合は作成も行います。"cd" と "mkdir" を合わせた動きをする。
※RUN では、cdもmkdirもできない
RUN
> コンテナの作成時に実行するコマンドを記述します。
CMD
> コンテナの起動時に実行するコマンドを記述します。
② Dockerイメージを作成する(コンテナをビルドする)
root@RascalRoom:~/app1# docker build -t develop1/nodejs . Sending build context to Docker daemon 10.24kB Step 1/15 : FROM node:latest ---> 6be2fabd4196 Step 2/15 : WORKDIR /work ---> Running in 8880844fdfb7 Removing intermediate container 8880844fdfb7 ---> 9aa99560bb7f Step 3/15 : RUN apt-get update ---> Running in 0e312c05d76b Ign:1 http://deb.debian.org/debian stretch InRelease Get:2 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB] Get:3 http://deb.debian.org/debian stretch Release [118 kB] Get:4 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB] Get:5 http://deb.debian.org/debian stretch Release.gpg [2434 B] Get:6 http://deb.debian.org/debian stretch-updates/main amd64 Packages [27.2 kB] Get:7 http://deb.debian.org/debian stretch/main amd64 Packages [7082 kB] Get:8 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [499 kB] Fetched 7914 kB in 1s (4197 kB/s) Reading package lists... Removing intermediate container 0e312c05d76b ---> 1f32203b9686 Step 4/15 : RUN apt-get install -y vim net-tools ssh mongodb ---> Running in f983922c68a5 Reading package lists... Building dependency tree... Reading state information... The following additional packages will be installed: cgmanager dbus dmsetup libapparmor1 libboost-chrono1.62.0 libboost-filesystem1.62.0 libboost-program-options1.62.0 libboost-regex1.62.0 libboost-system1.62.0 libboost-thread1.62.0 libcgmanager0 libcryptsetup4 libdbus-1-3 libdevmapper1.02.1 libgoogle-perftools4 libgpm2 libip4tc0 libkmod2 libnih-dbus1 libnih1 libpam-systemd libpcap0.8 libseccomp2 libsnappy1v5 libstemmer0d libtcmalloc-minimal4 libunwind8 libwrap0 libxmuu1 libyaml-cpp0.5v5 mongo-tools mongodb-clients mongodb-server ncurses-term openssh-server openssh-sftp-server systemd systemd-shim tcpd vim-common vim-runtime xauth xxd Suggested packages: default-dbus-session-bus | dbus-session-bus gpm molly-guard monkeysphere rssh ssh-askpass ufw systemd-ui systemd-container policykit-1 pm-utils ctags vim-doc vim-scripts The following NEW packages will be installed: cgmanager dbus dmsetup libapparmor1 libboost-chrono1.62.0 libboost-filesystem1.62.0 libboost-program-options1.62.0 libboost-regex1.62.0 libboost-system1.62.0 libboost-thread1.62.0 libcgmanager0 libcryptsetup4 libdevmapper1.02.1 libgoogle-perftools4 libgpm2 libip4tc0 libkmod2 libnih-dbus1 libnih1 libpam-systemd libpcap0.8 libseccomp2 libsnappy1v5 libstemmer0d libtcmalloc-minimal4 libunwind8 libwrap0 libxmuu1 libyaml-cpp0.5v5 mongo-tools mongodb mongodb-clients mongodb-server ncurses-term net-tools openssh-server openssh-sftp-server ssh systemd systemd-shim tcpd vim vim-common vim-runtime xauth xxd The following packages will be upgraded: libdbus-1-3 1 upgraded, 46 newly installed, 0 to remove and 3 not upgraded. Need to get 58.1 MB of archives. After this operation, 249 MB of additional disk space will be used. Get:1 http://deb.debian.org/debian stretch/main amd64 libapparmor1 amd64 2.11.0-3+deb9u2 [78.9 kB] Get:2 http://deb.debian.org/debian stretch/main amd64 dmsetup amd64 2:1.02.137-2 [107 kB] Get:3 http://deb.debian.org/debian stretch/main amd64 libdevmapper1.02.1 amd64 2:1.02.137-2 [170 kB] Get:4 http://deb.debian.org/debian stretch/main amd64 libcryptsetup4 amd64 2:1.7.3-4 [109 kB] Get:5 http://deb.debian.org/debian stretch/main amd64 libip4tc0 amd64 1.6.0+snapshot20161117-6 [67.8 kB] Get:6 http://deb.debian.org/debian stretch/main amd64 libkmod2 amd64 23-2 [48.1 kB] Get:7 http://deb.debian.org/debian stretch/main amd64 libseccomp2 amd64 2.3.1-2.1+deb9u1 [40.7 kB] Get:8 http://deb.debian.org/debian stretch/main amd64 systemd amd64 232-25+deb9u11 [2471 kB] Get:9 http://deb.debian.org/debian stretch/main amd64 openssh-sftp-server amd64 1:7.4p1-10+deb9u6 [39.7 kB] Get:10 http://deb.debian.org/debian stretch/main amd64 libwrap0 amd64 7.6.q-26 [58.2 kB] Get:11 http://deb.debian.org/debian stretch/main amd64 openssh-server amd64 1:7.4p1-10+deb9u6 [332 kB] Get:12 http://deb.debian.org/debian stretch/main amd64 ssh all 1:7.4p1-10+deb9u6 [189 kB] Get:13 http://deb.debian.org/debian stretch/main amd64 libgpm2 amd64 1.20.4-6.2+b1 [34.2 kB] Get:14 http://deb.debian.org/debian stretch/main amd64 libnih1 amd64 1.0.3-8 [125 kB] Get:15 http://deb.debian.org/debian stretch/main amd64 libnih-dbus1 amd64 1.0.3-8 [96.8 kB] Get:16 http://deb.debian.org/debian stretch/main amd64 libcgmanager0 amd64 0.41-2 [41.1 kB] Get:17 http://deb.debian.org/debian stretch/main amd64 cgmanager amd64 0.41-2 [84.0 kB] Get:18 http://deb.debian.org/debian stretch/main amd64 systemd-shim amd64 10-3 [20.0 kB] Get:19 http://deb.debian.org/debian stretch/main amd64 libpam-systemd amd64 232-25+deb9u11 [189 kB] Get:20 http://deb.debian.org/debian stretch/main amd64 ncurses-term all 6.0+20161126-1+deb9u2 [469 kB] Get:21 http://deb.debian.org/debian stretch/main amd64 libboost-system1.62.0 amd64 1.62.0+dfsg-4 [32.4 kB] Get:22 http://deb.debian.org/debian stretch/main amd64 libboost-chrono1.62.0 amd64 1.62.0+dfsg-4 [36.0 kB] Get:23 http://deb.debian.org/debian stretch/main amd64 libboost-filesystem1.62.0 amd64 1.62.0+dfsg-4 [63.2 kB] Get:24 http://deb.debian.org/debian stretch/main amd64 libboost-program-options1.62.0 amd64 1.62.0+dfsg-4 [159 kB] Get:25 http://deb.debian.org/debian stretch/main amd64 libboost-regex1.62.0 amd64 1.62.0+dfsg-4 [288 kB] Get:26 http://deb.debian.org/debian stretch/main amd64 libboost-thread1.62.0 amd64 1.62.0+dfsg-4 [71.5 kB] Get:27 http://deb.debian.org/debian stretch/main amd64 libtcmalloc-minimal4 amd64 2.5-2.2 [121 kB] Get:28 http://deb.debian.org/debian stretch/main amd64 libunwind8 amd64 1.1-4.1 [48.7 kB] Get:29 http://deb.debian.org/debian stretch/main amd64 libgoogle-perftools4 amd64 2.5-2.2 [224 kB] Get:30 http://deb.debian.org/debian stretch/main amd64 libpcap0.8 amd64 1.8.1-3 [138 kB] Get:31 http://deb.debian.org/debian stretch/main amd64 libstemmer0d amd64 0+svn585-1+b2 [63.3 kB] Get:32 http://deb.debian.org/debian stretch/main amd64 libxmuu1 amd64 2:1.1.2-2 [23.5 kB] Get:33 http://deb.debian.org/debian stretch/main amd64 libyaml-cpp0.5v5 amd64 0.5.2-4 [151 kB] Get:34 http://security.debian.org/debian-security stretch/updates/main amd64 xxd amd64 2:8.0.0197-4+deb9u3 [132 kB] Get:35 http://deb.debian.org/debian stretch/main amd64 mongo-tools amd64 3.2.11-1+b2 [12.2 MB] Get:36 http://security.debian.org/debian-security stretch/updates/main amd64 vim-common all 2:8.0.0197-4+deb9u3 [159 kB] Get:37 http://security.debian.org/debian-security stretch/updates/main amd64 libdbus-1-3 amd64 1.10.28-0+deb9u1 [195 kB] Get:38 http://security.debian.org/debian-security stretch/updates/main amd64 dbus amd64 1.10.28-0+deb9u1 [212 kB] Get:39 http://security.debian.org/debian-security stretch/updates/main amd64 vim-runtime all 2:8.0.0197-4+deb9u3 [5409 kB] Get:40 http://deb.debian.org/debian stretch/main amd64 libsnappy1v5 amd64 1.1.3-3 [51.0 kB] Get:41 http://deb.debian.org/debian stretch/main amd64 mongodb-clients amd64 1:3.2.11-2+deb9u1 [20.4 MB] Get:42 http://security.debian.org/debian-security stretch/updates/main amd64 vim amd64 2:8.0.0197-4+deb9u3 [1034 kB] Get:43 http://deb.debian.org/debian stretch/main amd64 mongodb-server amd64 1:3.2.11-2+deb9u1 [11.8 MB] Get:44 http://deb.debian.org/debian stretch/main amd64 mongodb amd64 1:3.2.11-2+deb9u1 [16.9 kB] Get:45 http://deb.debian.org/debian stretch/main amd64 net-tools amd64 1.60+git20161116.90da8a0-1 [248 kB] Get:46 http://deb.debian.org/debian stretch/main amd64 tcpd amd64 7.6.q-26 [23.3 kB] Get:47 http://deb.debian.org/debian stretch/main amd64 xauth amd64 1:1.0.9-1+b2 [39.6 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 58.1 MB in 6s (9636 kB/s) Selecting previously unselected package libapparmor1:amd64. (Reading database ... 29980 files and directories currently installed.) Preparing to unpack .../00-libapparmor1_2.11.0-3+deb9u2_amd64.deb ... Unpacking libapparmor1:amd64 (2.11.0-3+deb9u2) ... Selecting previously unselected package dmsetup. Preparing to unpack .../01-dmsetup_2%3a1.02.137-2_amd64.deb ... Unpacking dmsetup (2:1.02.137-2) ... Selecting previously unselected package libdevmapper1.02.1:amd64. Preparing to unpack .../02-libdevmapper1.02.1_2%3a1.02.137-2_amd64.deb ... Unpacking libdevmapper1.02.1:amd64 (2:1.02.137-2) ... Selecting previously unselected package libcryptsetup4:amd64. Preparing to unpack .../03-libcryptsetup4_2%3a1.7.3-4_amd64.deb ... Unpacking libcryptsetup4:amd64 (2:1.7.3-4) ... Selecting previously unselected package libip4tc0:amd64. Preparing to unpack .../04-libip4tc0_1.6.0+snapshot20161117-6_amd64.deb ... Unpacking libip4tc0:amd64 (1.6.0+snapshot20161117-6) ... Selecting previously unselected package libkmod2:amd64. Preparing to unpack .../05-libkmod2_23-2_amd64.deb ... Unpacking libkmod2:amd64 (23-2) ... Selecting previously unselected package libseccomp2:amd64. Preparing to unpack .../06-libseccomp2_2.3.1-2.1+deb9u1_amd64.deb ... Unpacking libseccomp2:amd64 (2.3.1-2.1+deb9u1) ... Selecting previously unselected package systemd. Preparing to unpack .../07-systemd_232-25+deb9u11_amd64.deb ... Unpacking systemd (232-25+deb9u11) ... Selecting previously unselected package openssh-sftp-server. Preparing to unpack .../08-openssh-sftp-server_1%3a7.4p1-10+deb9u6_amd64.deb ... Unpacking openssh-sftp-server (1:7.4p1-10+deb9u6) ... Selecting previously unselected package libwrap0:amd64. Preparing to unpack .../09-libwrap0_7.6.q-26_amd64.deb ... Unpacking libwrap0:amd64 (7.6.q-26) ... Selecting previously unselected package openssh-server. Preparing to unpack .../10-openssh-server_1%3a7.4p1-10+deb9u6_amd64.deb ... Unpacking openssh-server (1:7.4p1-10+deb9u6) ... Selecting previously unselected package ssh. Preparing to unpack .../11-ssh_1%3a7.4p1-10+deb9u6_all.deb ... Unpacking ssh (1:7.4p1-10+deb9u6) ... Selecting previously unselected package xxd. Preparing to unpack .../12-xxd_2%3a8.0.0197-4+deb9u3_amd64.deb ... Unpacking xxd (2:8.0.0197-4+deb9u3) ... Selecting previously unselected package vim-common. Preparing to unpack .../13-vim-common_2%3a8.0.0197-4+deb9u3_all.deb ... Unpacking vim-common (2:8.0.0197-4+deb9u3) ... Preparing to unpack .../14-libdbus-1-3_1.10.28-0+deb9u1_amd64.deb ... Unpacking libdbus-1-3:amd64 (1.10.28-0+deb9u1) over (1.10.26-0+deb9u1) ... Selecting previously unselected package dbus. Preparing to unpack .../15-dbus_1.10.28-0+deb9u1_amd64.deb ... Unpacking dbus (1.10.28-0+deb9u1) ... Selecting previously unselected package libgpm2:amd64. Preparing to unpack .../16-libgpm2_1.20.4-6.2+b1_amd64.deb ... Unpacking libgpm2:amd64 (1.20.4-6.2+b1) ... Selecting previously unselected package libnih1. Preparing to unpack .../17-libnih1_1.0.3-8_amd64.deb ... Unpacking libnih1 (1.0.3-8) ... Selecting previously unselected package libnih-dbus1. Preparing to unpack .../18-libnih-dbus1_1.0.3-8_amd64.deb ... Unpacking libnih-dbus1 (1.0.3-8) ... Selecting previously unselected package libcgmanager0:amd64. Preparing to unpack .../19-libcgmanager0_0.41-2_amd64.deb ... Unpacking libcgmanager0:amd64 (0.41-2) ... Selecting previously unselected package cgmanager. Preparing to unpack .../20-cgmanager_0.41-2_amd64.deb ... Unpacking cgmanager (0.41-2) ... Selecting previously unselected package systemd-shim. Preparing to unpack .../21-systemd-shim_10-3_amd64.deb ... Adding 'diversion of /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service to /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.systemd by systemd-shim' Unpacking systemd-shim (10-3) ... Selecting previously unselected package libpam-systemd:amd64. Preparing to unpack .../22-libpam-systemd_232-25+deb9u11_amd64.deb ... Unpacking libpam-systemd:amd64 (232-25+deb9u11) ... Selecting previously unselected package ncurses-term. Preparing to unpack .../23-ncurses-term_6.0+20161126-1+deb9u2_all.deb ... Unpacking ncurses-term (6.0+20161126-1+deb9u2) ... Selecting previously unselected package libboost-system1.62.0:amd64. Preparing to unpack .../24-libboost-system1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-system1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libboost-chrono1.62.0:amd64. Preparing to unpack .../25-libboost-chrono1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-chrono1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libboost-filesystem1.62.0:amd64. Preparing to unpack .../26-libboost-filesystem1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-filesystem1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libboost-program-options1.62.0:amd64. Preparing to unpack .../27-libboost-program-options1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-program-options1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libboost-regex1.62.0:amd64. Preparing to unpack .../28-libboost-regex1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-regex1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libboost-thread1.62.0:amd64. Preparing to unpack .../29-libboost-thread1.62.0_1.62.0+dfsg-4_amd64.deb ... Unpacking libboost-thread1.62.0:amd64 (1.62.0+dfsg-4) ... Selecting previously unselected package libtcmalloc-minimal4. Preparing to unpack .../30-libtcmalloc-minimal4_2.5-2.2_amd64.deb ... Unpacking libtcmalloc-minimal4 (2.5-2.2) ... Selecting previously unselected package libunwind8. Preparing to unpack .../31-libunwind8_1.1-4.1_amd64.deb ... Unpacking libunwind8 (1.1-4.1) ... Selecting previously unselected package libgoogle-perftools4. Preparing to unpack .../32-libgoogle-perftools4_2.5-2.2_amd64.deb ... Unpacking libgoogle-perftools4 (2.5-2.2) ... Selecting previously unselected package libpcap0.8:amd64. Preparing to unpack .../33-libpcap0.8_1.8.1-3_amd64.deb ... Unpacking libpcap0.8:amd64 (1.8.1-3) ... Selecting previously unselected package libstemmer0d:amd64. Preparing to unpack .../34-libstemmer0d_0+svn585-1+b2_amd64.deb ... Unpacking libstemmer0d:amd64 (0+svn585-1+b2) ... Selecting previously unselected package libxmuu1:amd64. Preparing to unpack .../35-libxmuu1_2%3a1.1.2-2_amd64.deb ... Unpacking libxmuu1:amd64 (2:1.1.2-2) ... Selecting previously unselected package libyaml-cpp0.5v5:amd64. Preparing to unpack .../36-libyaml-cpp0.5v5_0.5.2-4_amd64.deb ... Unpacking libyaml-cpp0.5v5:amd64 (0.5.2-4) ... Selecting previously unselected package mongo-tools. Preparing to unpack .../37-mongo-tools_3.2.11-1+b2_amd64.deb ... Unpacking mongo-tools (3.2.11-1+b2) ... Selecting previously unselected package libsnappy1v5:amd64. Preparing to unpack .../38-libsnappy1v5_1.1.3-3_amd64.deb ... Unpacking libsnappy1v5:amd64 (1.1.3-3) ... Selecting previously unselected package mongodb-clients. Preparing to unpack .../39-mongodb-clients_1%3a3.2.11-2+deb9u1_amd64.deb ... Unpacking mongodb-clients (1:3.2.11-2+deb9u1) ... Selecting previously unselected package mongodb-server. Preparing to unpack .../40-mongodb-server_1%3a3.2.11-2+deb9u1_amd64.deb ... Unpacking mongodb-server (1:3.2.11-2+deb9u1) ... Selecting previously unselected package mongodb. Preparing to unpack .../41-mongodb_1%3a3.2.11-2+deb9u1_amd64.deb ... Unpacking mongodb (1:3.2.11-2+deb9u1) ... Selecting previously unselected package net-tools. Preparing to unpack .../42-net-tools_1.60+git20161116.90da8a0-1_amd64.deb ... Unpacking net-tools (1.60+git20161116.90da8a0-1) ... Selecting previously unselected package tcpd. Preparing to unpack .../43-tcpd_7.6.q-26_amd64.deb ... Unpacking tcpd (7.6.q-26) ... Selecting previously unselected package vim-runtime. Preparing to unpack .../44-vim-runtime_2%3a8.0.0197-4+deb9u3_all.deb ... Adding 'diversion of /usr/share/vim/vim80/doc/help.txt to /usr/share/vim/vim80/doc/help.txt.vim-tiny by vim-runtime' Adding 'diversion of /usr/share/vim/vim80/doc/tags to /usr/share/vim/vim80/doc/tags.vim-tiny by vim-runtime' Unpacking vim-runtime (2:8.0.0197-4+deb9u3) ... Selecting previously unselected package vim. Preparing to unpack .../45-vim_2%3a8.0.0197-4+deb9u3_amd64.deb ... Unpacking vim (2:8.0.0197-4+deb9u3) ... Selecting previously unselected package xauth. Preparing to unpack .../46-xauth_1%3a1.0.9-1+b2_amd64.deb ... Unpacking xauth (1:1.0.9-1+b2) ... Setting up ncurses-term (6.0+20161126-1+deb9u2) ... Setting up libip4tc0:amd64 (1.6.0+snapshot20161117-6) ... Processing triggers for mime-support (3.60) ... Setting up xxd (2:8.0.0197-4+deb9u3) ... Setting up libgpm2:amd64 (1.20.4-6.2+b1) ... Setting up libboost-program-options1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up libboost-regex1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up libstemmer0d:amd64 (0+svn585-1+b2) ... Setting up libkmod2:amd64 (23-2) ... Setting up libxmuu1:amd64 (2:1.1.2-2) ... Setting up xauth (1:1.0.9-1+b2) ... Setting up libtcmalloc-minimal4 (2.5-2.2) ... Setting up libunwind8 (1.1-4.1) ... Setting up openssh-sftp-server (1:7.4p1-10+deb9u6) ... Processing triggers for libc-bin (2.24-11+deb9u4) ... Setting up libseccomp2:amd64 (2.3.1-2.1+deb9u1) ... Setting up libapparmor1:amd64 (2.11.0-3+deb9u2) ... Setting up libsnappy1v5:amd64 (1.1.3-3) ... Setting up vim-common (2:8.0.0197-4+deb9u3) ... Setting up vim-runtime (2:8.0.0197-4+deb9u3) ... Setting up libyaml-cpp0.5v5:amd64 (0.5.2-4) ... Setting up net-tools (1.60+git20161116.90da8a0-1) ... Processing triggers for hicolor-icon-theme (0.15-1) ... Setting up libnih1 (1.0.3-8) ... Setting up libdbus-1-3:amd64 (1.10.28-0+deb9u1) ... Setting up libboost-system1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up mongo-tools (3.2.11-1+b2) ... Setting up libnih-dbus1 (1.0.3-8) ... Setting up libwrap0:amd64 (7.6.q-26) ... Setting up libpcap0.8:amd64 (1.8.1-3) ... Setting up libcgmanager0:amd64 (0.41-2) ... Setting up vim (2:8.0.0197-4+deb9u3) ... update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode Setting up libboost-thread1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up tcpd (7.6.q-26) ... Setting up cgmanager (0.41-2) ... Created symlink /etc/systemd/system/multi-user.target.wants/cgmanager.service → /lib/systemd/system/cgmanager.service. Created symlink /etc/systemd/system/multi-user.target.wants/cgproxy.service → /lib/systemd/system/cgproxy.service. invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Setting up openssh-server (1:7.4p1-10+deb9u6) ... debconf: unable to initialize frontend: Dialog debconf: (TERM is not set, so the dialog frontend is not usable.) debconf: falling back to frontend: Readline Creating config file /etc/ssh/sshd_config with new version Creating SSH2 RSA key; this may take some time ... 2048 SHA256:BjwxpnabZrxeLa5yX5ekiWceWd4n3dWhoG+Q5GhGVXo root@f983922c68a5 (RSA) Creating SSH2 ECDSA key; this may take some time ... 256 SHA256:dSiw+gdyTfjvvbh8bRzWPuFdRG8qaeV1/bAbNDPkooc root@f983922c68a5 (ECDSA) Creating SSH2 ED25519 key; this may take some time ... 256 SHA256:OarFUIEJVK3mFHYYGbb5vrYZWBje+Tqr40/TSyW/MfY root@f983922c68a5 (ED25519) Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service. Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service. invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Setting up libgoogle-perftools4 (2.5-2.2) ... Setting up libboost-filesystem1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up dbus (1.10.28-0+deb9u1) ... invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Setting up systemd-shim (10-3) ... Setting up libboost-chrono1.62.0:amd64 (1.62.0+dfsg-4) ... Setting up mongodb-clients (1:3.2.11-2+deb9u1) ... Setting up mongodb-server (1:3.2.11-2+deb9u1) ... Created symlink /etc/systemd/system/multi-user.target.wants/mongodb.service → /lib/systemd/system/mongodb.service. invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Setting up ssh (1:7.4p1-10+deb9u6) ... Setting up mongodb (1:3.2.11-2+deb9u1) ... Setting up libdevmapper1.02.1:amd64 (2:1.02.137-2) ... Setting up dmsetup (2:1.02.137-2) ... Setting up libcryptsetup4:amd64 (2:1.7.3-4) ... Setting up systemd (232-25+deb9u11) ... Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service → /lib/systemd/system/getty@.service. Created symlink /etc/systemd/system/multi-user.target.wants/remote-fs.target → /lib/systemd/system/remote-fs.target. Created symlink /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service → /lib/systemd/system/systemd-timesyncd.service. Adding group `systemd-journal' (GID 104) ... Done. Setting up libpam-systemd:amd64 (232-25+deb9u11) ... debconf: unable to initialize frontend: Dialog debconf: (TERM is not set, so the dialog frontend is not usable.) debconf: falling back to frontend: Readline Processing triggers for libc-bin (2.24-11+deb9u4) ... Processing triggers for dbus (1.10.28-0+deb9u1) ... Removing intermediate container f983922c68a5 ---> 839c2d77c183 Step 5/15 : RUN npm -g install forever ---> Running in e4259122d396 /usr/local/bin/forever -> /usr/local/lib/node_modules/forever/bin/forever npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/forever/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + forever@1.0.0 added 245 packages from 151 contributors in 6.155s Removing intermediate container e4259122d396 ---> a737b3f4b107 Step 6/15 : RUN npm -g install sails ---> Running in b5742f1db140 /usr/local/bin/sails -> /usr/local/lib/node_modules/sails/bin/sails.js + sails@1.2.3 added 205 packages from 113 contributors in 9.34s Removing intermediate container b5742f1db140 ---> 6d19ea550d6f Step 7/15 : RUN echo "export LANG=C.UTF-8" >> /etc/profile.d/lang.sh ---> Running in c0b04e4a497f Removing intermediate container c0b04e4a497f ---> 8ca6ccade67f Step 8/15 : RUN echo "export LANGUAGE=en_US:" >> /etc/profile.d/lang.sh ---> Running in a6361fa3400c Removing intermediate container a6361fa3400c ---> 05e8591b0e8a Step 9/15 : RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config ---> Running in 5ccad6a110b1 Removing intermediate container 5ccad6a110b1 ---> 91de7ee7da93 Step 10/15 : RUN echo "root:rootpass" | chpasswd -m ---> Running in bfe000cf5de9 Removing intermediate container bfe000cf5de9 ---> abf805b18f27 Step 11/15 : RUN echo 2 | sails new app --fast ---> Running in 5f2f798dbadf Choose a template for your new Sails app: 1. Web App ・ Extensible project with auth, login, & password recovery 2. Empty ・ An empty Sails app, yours to configure (type "?" for help, or <CTRL+C> to cancel) ? info: Created a new Sails app `app`! (you will need to cd in and run `npm install`) Removing intermediate container 5f2f798dbadf ---> d2bfc8acd632 Step 12/15 : WORKDIR /work/app ---> Running in 94f690cbf08b Removing intermediate container 94f690cbf08b ---> 9b1bc8a95e50 Step 13/15 : RUN npm install ---> Running in 60179cb4f4aa > core-js@2.6.7 postinstall /work/app/node_modules/sails-hook-grunt/node_modules/core-js > node scripts/postinstall added 866 packages from 713 contributors in 11.768s Removing intermediate container 60179cb4f4aa ---> 2ba0bc4d2fca Step 14/15 : RUN npm install sails-mongo --save ---> Running in c04b3b33a6b9 + sails-mongo@1.0.1 added 15 packages from 10 contributors in 3.749s Removing intermediate container c04b3b33a6b9 ---> f604a1fe4a56 Step 15/15 : CMD ["bash"] ---> Running in eceda74a97f9 Removing intermediate container eceda74a97f9 ---> a1b24481172f Successfully built a1b24481172f Successfully tagged develop1/nodejs:latest
③ Dockerイメージからコンテナを作成し起動する
root@RascalRoom:~/app1# docker run --name develop1 -p 1337:1337 -it develop1/node.js
--name コンテナに名前を付けます。
-p ポートフォワードを定義します。
{ コンテナのポート }:{ ホストのポート }
-it おまじない。
--rm オプションをつけることで、コンテナのコンソールから抜けた際に、コンテナを削除します。
root@RascalRoom:~/app1# docker run --rm --name develop1 -p 1337:1337 -it develop1/node.js
Portainer
CUI(コマンドライン)に慣れていない方には、この "Portainer" がおすすめです。
ブラウザからDockerを操作することができるようになり、管理が非常に楽になります。
Dockerを使い慣れている方でも、管理面から導入を検討してもいいかと思います。
導入手順
導入にはDockerを使うので先に環境は作っておきましょう。
(Dockerの管理をDockerコンテナ上で行います。)
インストールは簡単です。何も考えずに以下を実行してみましょう。
root@RascalRoom:~/app1# docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
ブラウザで接続してみると、まず "admin" ユーザーのパスワード登録を求められます。
登録が完了したら、以下のログイン画面が表示されるのでログインします。
ブラウザ上で目に見えて管理ができるので便利じゃないですか?
ネットにはこのようなアプリケーションが既にセットアップされたDockerイメージがたくさん転がっているので、いろいろ触って試してみるのも面白いですよ。
まとめ
Dockerで開発環境を用意するとほんとに楽。
作成したDockerfileをGitHubなどで管理・公開してもいいですし、
流行りの "infrastructure as code" にもなりますね。
他にも、VirualBoxをベースとしたVagrantなど、いろんな環境が提供されていますので、各々、自分に合ったものを見つけてみても楽しいかもしれません。
次回は、「Node.js」について紹介していきます。