LoginSignup
35
35

More than 5 years have passed since last update.

dockerでhubotが動作する環境を作る

Last updated at Posted at 2016-01-14

初投稿です。tuboneです。

hubotはnode.jsとnpmで動作しますが、node.jsの環境構築がめんどくさかったのでとりあえずdockerでnode.jsの環境を構築して、hubotのインストールまでやっていきたいと思います。非常に簡単に構築できますが、つまずいた点がいくつかあったので(海外のリファレンスでもanswerまとまっていなかったので)まとめてみたいと思います。

使用したサーバ環境:CentOS release 6.7 (Final)


dockerでnode.jsが動く環境を作る

dockerのインストール

まずdockerが動かなければ意味が無いのでdockerを入れて下さい。
epelリポジトリからyumが便利です。

# rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
# yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum -y install docker-io

注意したいのは"docker" ではなく "docker-io"です。

dockerのサービスを起動します。

# service docker start
# chkconfig docker on

node.jsのコンテナを作る

node.jsのイメージはdokerhubに公式があります。

今回はそれを使います。

# docker pull node

イメージが入ったことを確認して下さい。

# docker images
結果
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
node                latest              811aa8ed56dd        1 hours ago        643 MB

このイメージを利用してコンテナを作成します。
hubotの設定もあるのでbashを起動します。

nameでコンテナにhubot1という名前をつけました

$ docker run -it --name "hubot1" node /bin/bash

するとhubot1のbashに切り替わります。

結果
root@811aa8ed56dd:/# #hubot1のbashです

hubotを導入する

Yeomanでgenerator-hubotをインストール

最新のhubotはYeomanをつかって導入しますので

root@811aa8ed56dd:/# npm install -g yo generator-hubot

とやるとなにやらダウンロードし始めます。さらに

root@811aa8ed56dd:/# npm list -g generator-hubot yo

npm info it worked if it ends with ok
npm info using npm@3.3.12
npm info using node@v5.4.1
/usr/local/lib
+-- generator-hubot@0.3.1
`-- yo@1.6.0

npm info ok

これでyoと generator-hubot のインストールができました。

hubotを実際のディレクトリにいれる作業

このままディレクトリを作成しyo しようとするとエラーがでます。
(自分はここでかなりつまずきました)

rootのままインストールしようとするとこんなエラーが出てきます。

Error: EACCES: permission denied, open '/root/.config/configstore/insight-yo.json' You don't have access to this file.

permission deniedだから権限がおかしいかと思ってchmod chownしてもなんか上手くいかないし、そもそもこんなファイルないし…
かなり困りました。

dockerでは基本的にrootユーザで作業しますが、それが悪かったようです。

まずhubot用の一般ユーザを作り、そのユーザーのhomeディレクトリで
作業します。

user追加
root@811aa8ed56dd:/# adduser myhubot
Adding user `myhubot' ...
Adding new group `myhubot' (1000) ...
Adding new user `myhubot' (1000) with group `myhubot' ...
Creating home directory `/home/myhubot' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for myhubot
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

ユーザをrootからmyhubot に切り替えディレクトリも切り替えちゃってください。

root@811aa8ed56dd:/# su myhubot
myhubot@811aa8ed56dd:/$ cd ~
myhubot@811aa8ed56dd:/$ pwd
/home/myhubot

で、

myhubot@811aa8ed56dd:/$ yo hubot

でmyhubotができました!
あとは画面に則って情報を入力すればいいです。
(ownerとかbotnameとか)

とりあえずお疲れ様でした。

将来的には孤独を忘れさせる便利対話botを作りたいですね。

35
35
1

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