Ubunt14にDockerをインスツール

Ubunt14にDockerをインスツールしてみる

https://docs.docker.com/installation/ubuntulinux/
http://qiita.com/koara-local/items/ee887bab8c7186d00a88

を、参考に行う

端末の環境を確認

uname -r 

3.13.0-24-generic

wget -qO- https://get.docker.com/ | sh

インストールが、完了した時
最後に表示されるメッセージする従い
ユーザーをdockerグループに追加する
(xxxxxには、ユーザ名を。。)

sudo usermod -aG docker xxxxx

インストールされたか確認

docker --version

1.8.2が、インスツールされたよう

Docker version 1.8.2, build 0a8c2e3

ubuntu14.04のコンテナを作ってみる

docker run -i -t ubuntu:14.04 /bin/bash

下記、エラーがでた

Post http:///var/run/docker.sock/v1.20/containers/create: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

一度、電源を落として、再起動してみる

docker run -i -t ubuntu:14.04 /bin/bash
d3a1f33e8a5a: Pull complete 
c22013c84729: Pull complete
  :
  : 
Digest: sha256:b08e2d47c4629f8f9d1ae11eda8fdb3aeaf3f84de7cf19e4bb9395eaad006bd9
Status: Downloaded newer image for ubuntu:14.04
root@508cb9c16fe6:/#

今度はできた。
一度、抜け

exit

イメージを確認

docker images

ubuntu 14.04
が、登録されている

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              14.04               91e54dfb1179        5 weeks ago         188.4 MB

centos6のコンテナを作ってみる

docker run -i -t centos:centos6 /bin/bash
Unable to find image 'centos:centos6' locally
centos6: Pulling from library/centos
47d44cb6f252: Pull complete 
6a7b54515901: Pull complete 
e788880c8cfa: Pull complete 
1debf8fb53e6: Pull complete 
72703a0520b7: Pull complete 
Digest: sha256:efa5de1eed533dd620ba3ae1d1f046c02a874d88860ff7a36a1dcbfe4ca8cff6
Status: Downloaded newer image for centos:centos6
   :
[root@808c71aca99f /]# 

無事、ログインできた

一度、抜け

exit

イメージを確認

docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6 72703a0520b7 2 weeks ago 190.6 MB
ubuntu 14.04 91e54dfb1179 5 weeks ago 188.4 MB

centos centos6
が、登録されている

コンテナを使ってみる

docker run -i -t centos:centos6 /bin/bash

Apacheをインスツールしてみる

[root@808c71aca99f /]#
yum -y install httpd
service httpd status
service httpd start

domain name, using 172.17.0.5 for ServerName
と、表示されたので、
ブラウザから172.17.0.5を
アクセスしてみる

無事、Apacheの画面が表示

コンテナないのデータの扱いを確認してみる
(データの永続性)
試しに、データをsample.txtを作って見る

cd home
echo hello > sample.txt
ls

cat sample.txt

サンプルのデータができた

一度終了する

exit
docker run -i -t centos:centos6 /bin/bash
cd home
ls

表示されない
作成したデータは、保存されないことを確認

exit

操作した内容を、再利用するために、
イメージを作成してみる

手順は、

コンテナ起動
ターミナルで操作
ターミナルから抜け(exit)
動作済コンテナから、イメージ作成

作成イメージからコンテナ起動
内容確認

となります

docker run -i -t centos:centos6 /bin/bash
cd home
echo hello > sample.txt
ls

cat sample.txt

サンプルのデータができた

一度終了する

exit

最後に実行した、コンテナを調べる

docker ps -a -n=1
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
e8cb2d1063b4        centos:centos6      "/bin/bash"         52 seconds ago      Exited (0) 18 seconds ago                       suspicious_goldstine

最後に実行したコンテナから、CONTAINER IDを読み取り
docker commit CONTAINER ID 登録名
で、新しいイメージを作成する
CONTAINER IDは、特定できればよく、重複していなければ、上位5桁で大丈夫
登録名は、名前/機能で作成

docker commit e8cb2d user/sample

作成したイメージを確認

docker images

登録できているか一覧を確認

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
user/sample         latest              1a67f695ec62        17 seconds ago      190.6 MB
centos              centos6             72703a0520b7        2 weeks ago         190.6 MB
ubuntu              14.04               91e54dfb1179        5 weeks ago         188.4 MB

作成したイメージを起動してみる

docker run -i -t user/sample /bin/bash

作成した内容が残っているか確認する

cd /home
ls
cat sample.txt

Ubuntu Desktop のDockerを立ち上げ、VNCとSSHで接続する

参考

DockerでUbuntuデスクトップを使おう


http://qiita.com/fireowl11/items/7a22510bc8951342d031

イメージを読み込む

docker pull dorowu/ubuntu-desktop-lxde-vnc

コンテナ起動

docker run --name ubuntu -d -p 6080:6080 -p 2233:22 dorowu/ubuntu-desktop-lxde-vnc

名前が重複するとエラーになる

Error response from daemon: Conflict. The name "ubuntu" is already

一度削除してから、行う

docker rm ubuntu

ブラウザからアクセス

http://localhost:6080/vnc.html

User: ubuntu Pass: ubuntu
で、接続する
下段、一番左のアイコンをクリック
Accessories>LXTermnal
で、ターミナルを開く
SSHを確認

server ssh status

停止している

sshd is not running

本体側にて

docker ps

で、起動しているIDを調べる

CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS                                          NAMES
a370262e8fbb        dorowu/ubuntu-desktop-lxde-vnc   "/startup.sh"       3 minutes ago       Up 3 minutes        0.0.0.0:6080->6080/tcp, 0.0.0.0:2233->22/tcp   romantic_kalam

ID(上記の場合はa37026)を指定して、sshを起動する

docker exec a37026 service ssh restart

または、ラベル名をつけたので、ラベルで指定も可能

docker exec ubuntu service ssh restart

ブラウザ側の端末で起動を確認

server ssh status

起動している

sshd is running

端末から、SSHで接続

ssh -p 2233 ubuntu@localhost

を入力また、1回めは

Are you sure you want to continue connecting (yes/no)? yes

ときかれるので、
yes
とする

Passwordを聞かれるので
ubuntu
とする

下記のような感じで
端末から、SSHにて接続ができた

ssh -p 2233 ubuntu@localhost
The authenticity of host '[localhost]:2233 ([127.0.0.1]:2233)' can't be established.
ECDSA key fingerprint is d0:dc:04:f4:cb:92:67:34:d3:6e:ba:d7:b1:2f:3d:4e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2233' (ECDSA) to the list of known hosts.
ubuntu@localhost's password: ubuntu
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.2.0-77-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
ubuntu@a370262e8fbb:~$

無事、SSHで接続ができ、
ブラウザからのDesktop画面への接続もできました

SSHが接続できたので、Chromeブラウザを組み込んでみる

SSHの端末から

sudo apt-get update
sudo apt-get install wget
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

完了したら、ブラウザの左アイコンより
internet
の項目に、Google Chrome
が追加になる
選択することで、
Google Chrome
が、起動する

端末から、Docker仮想DeskTopへのファイル転送にはrsyncで可能

まず、Docker仮想DeskTopへ、rsyncをインストール

Docker仮想DeskTopへ入り

ssh -p 2233 ubuntu@localhost

rsyncをインストール

sudo apt-get install rsync
exit

端末側から送信したいデータPath(例:xxxx.txt)を指定し転送

rsync -e "ssh -p 2233" xxxx.txt ubuntu@localhost:/home/ubuntu

仮想端末でselenium-webdriver(Ruby)を起動してみる
はじめから、インストールする

docker stop ubuntu
docker rm ubuntu
docker run --name ubuntu -d -p 6080:6080 -p 2233:22 dorowu/ubuntu-desktop-lxde-vnc
docker exec ubuntu service ssh restart
ssh -p 2233 ubuntu@localhost
    password:  ubuntu
sudo apt-get update
    ubuntu:  ubuntu
LANG=en_US.UTF-8
sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales
sudo apt-get -y install vim
sudo apt-get -y install software-properties-common
sudo apt-add-repository -y ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get -y install ruby2.2
sudo apt-get -y install ruby2.2-dev
sudo gem install selenium-webdriver
sudo apt-get -y install wget
sudo apt-get -y install unzip
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
sudo wget http://chromedriver.storage.googleapis.com/2.13/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip
sudo cp chromedriver /usr/local/bin
sudo chmod +x /usr/local/bin/chromedriver
rm chromedriver
rm chromedriver_linux64.zip
sudo apt-get -f install
sudo apt-get -y install rsync
mkdir /home/ubuntu/ruby
exit
vi google.rb

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.navigate.to "https://www.google.com"
driver.quit
rsync -e "ssh -p 2233" google.rb ubuntu@localhost:/home/ubuntu/ruby

ssh -p 2233 ubuntu@localhost
cd ruby
ruby google.rb

仮想端末より
LXTerminal

cd ruby
ruby google.rb

Chromeが立ち上がれ、
Googleが一瞬、表示されれば完了