ラベル コンテナ の投稿を表示しています。 すべての投稿を表示
ラベル コンテナ の投稿を表示しています。 すべての投稿を表示

LXC:WSL上でLXCを実行してみる


WSL上でLXCを実行してみる

第1回 LXCとコンテナの基本 | gihyo.jp

LXC:LinuX Containerの略で、linuxcontainers.org で開発されているコンテナを扱うためのソフトウェア、というやつらしい。
WSL上でLXCが動くのか試してみた。

1. インストール
sudo apt-get install lxc

2. コンテナ環境の作成
sudo lxc-create -t ubuntu -n ubuntu01
"-t ubuntu" - template指定。Ubuntuのテンプレートを使ってコンテナを作る
"-n ubuntu01" - コンテナ名を ubuntu01 にする

3. コンテナを起動
sudo lxc-start -n ubuntu01 -d
"-n ubuntu01" - ubuntu01 という名前のコンテナを指定
"-d" - detached mode(バックグラウンド起動)
コマンド実行しても特に何も起こらない

4. 起動確認
LCXコンテナの一覧を表示
sudo lxc-ls --fancy
"--fancy" - 詳細表示

実行結果:
xxx@hppc:~$ sudo lxc-ls --fancy
NAME     STATE   AUTOSTART GROUPS IPV4       IPV6 UNPRIVILEGED
ubuntu01 RUNNING 0         -      10.0.3.186 -    false      
    
STATEが"RUNNING"ということでコンテナは起動している

5. コンテナに接続
lxc-createコマンドで"-t ubuntu"でUbuntuコンテナを作成した場合、デフォルトで"ubuntu"ユーザー(ubuntu)が作成される
sudo lxc-console -n ubuntu01
"-n ubuntu01" - ubuntu01 という名前のコンテナを指定

コマンド実行すると "ubuntu01 login:"となるので "ubuntu"、パスワード"ubuntu"でログインする。
コンソールから抜けるには [CTRL]+[a] を押した後に [q] を入力する。

6. コンテナの終了
コンテナを終了するにはコンソールにログインした状態で "sudo shutdown" コマンドを実行、または
コンソールの外で "sudo lxc-stop -n ubuntu01" を実行する。


LXC, WSL

用語:サイドカー

サイドカー
sidecar

Kubernetesポッド内のアプリケーションコンテナと連動する独立したコンテナ
プリケーションを助ける機能を果たすもの

https://www.nginx.co.jp/resources/glossary/sidecar/

Docker #7:仮想上にインストール可能か?(2)

■サンプルプロジェクトを実行してみる

1) Docker Quickstart Terminal
"git clone https://github.com/dockersamples/node-bulletin-board" を実行
→ エラーになってしまう。
これはどちらかというと git の問題か?
user@DESKTOP-S0KA939 MINGW64 /c/Program Files/Docker Toolbox
$ git clone https://github.com/dockersamples/node-bulletin-board
fatal: could not create work tree dir 'node-bulletin-board': Permission denied

ダウンロードするフォルダを変更することにした。
ホームディレクトリに "sample" フォルダを作成し、そこにダウンロードする。
user@DESKTOP-S0KA939 MINGW64 /c/Program Files/Docker Toolbox
$ cd ~

user@DESKTOP-S0KA939 MINGW64 ~
$ mkdir sample                                                                                                          

user@DESKTOP-S0KA939 MINGW64 ~
$ cd sample

user@DESKTOP-S0KA939 MINGW64 ~/sample
$ git clone https://github.com/dockersamples/node-bulletin-board                                                        Cloning into 'node-bulletin-board'...
remote: Enumerating objects: 124, done.
Receiving objects:  85% (106/124)
Receiving objects: 100% (124/124), 185.01 KiB | 0 bytes/s, done.
Resolving deltas: 100% (54/54), done.
Checking connectivity... done.
→ 成功

2) ビルド
"cd node-bulletin-board/bulletin-board-app"
"docker build --tag bulletinboard:1.0 ." を実行
user@DESKTOP-S0KA939 MINGW64 ~/sample
$ cd node-bulletin-board/bulletin-board-app

user@DESKTOP-S0KA939 MINGW64 ~/sample/node-bulletin-board/bulletin-board-app (master)
$ docker build --tag bulletinboard:1.0 .
Sending build context to Docker daemon  45.57kB
Step 1/7 : FROM node:current-slim
current-slim: Pulling from library/node
7d2977b12acb: Pull complete                                                                                             23e9a36a6e2d: Pull complete                                                                                             831103f0eed4: Pull complete                                                                                             f172d5646bed: Pull complete                                                                                             9f1d0c9b6ec5: Pull complete                                                                                             Digest: sha256:4f837156a4bc43b6c8af7195dd7dbfc0b46e6f3515f777e2cb53139dc4faee33
Status: Downloaded newer image for node:current-slim
 ---> 0e2e78467169
Step 2/7 : WORKDIR /usr/src/app
 ---> Running in 7d1f9feb06ec
Removing intermediate container 7d1f9feb06ec
 ---> 9fd234813d82
Step 3/7 : COPY package.json .
 ---> dae0e8b18c8e
Step 4/7 : RUN npm install
 ---> Running in ffb0d71c37be

> ejs@2.7.4 postinstall /usr/src/app/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN vue-event-bulletin@1.0.0 No repository field.
npm WARN The package morgan is included as both a dev and production dependency.

added 91 packages from 168 contributors and audited 92 packages in 21.23s
found 0 vulnerabilities


Removing intermediate container ffb0d71c37be
 ---> cf16b502eb47
Step 5/7 : EXPOSE 8080
 ---> Running in 1c73e9f6b526
Removing intermediate container 1c73e9f6b526
 ---> 2a493a5d8a48
Step 6/7 : CMD [ "npm", "start" ]
 ---> Running in 7124aec587d9
Removing intermediate container 7124aec587d9
 ---> c4f20714d4b2
Step 7/7 : COPY . .
 ---> 9a6ac0d7f00d
Successfully built 9a6ac0d7f00d
Successfully tagged bulletinboard:1.0
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

3) 実行
"docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0" を実行
user@DESKTOP-S0KA939 MINGW64 ~/sample/node-bulletin-board/bulletin-board-app (master)
$ docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
ac9d66b2d8f7f0e5d25a9cafb470c6295c908ac3d61c75e21c01be42e03229fc

"docker-machine ls"コマンドでIPアドレスを確認して
user@DESKTOP-S0KA939 MINGW64 ~/sample/node-bulletin-board/bulletin-board-app (master)
$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v19.03.5

ブラウザで上記確認したipの8000番ポートへアクセス
"http://192.168.99.100:8000"




Docker, git

* Docker #6:仮想上にインストール可能か?

VirtualBox上のWindows10にDocker Toolboxはインストール可能か?

■ホスト
・ホストOS : Windows 10 1909 (18363.900)
・CPU : i9-9900K

■ゲスト
・ゲストOS : Windows 10 1909 (18363.900)
・ゲストOS プロセッサ設定 "ネステッドVT-x/AMD-Vを有効化" にチェックを付ける

■動作確認
1) Docker Toolbox = すべて既定値でインストール
→ インストールは成功

2) Docker Quickstart Terminal 起動
→ 問題なし

3) サンプル実行
"docker run hello-world" を実行
→ 問題なし



Docker, 2020.06.21

Docker #5:Docker Hubへの登録 (2)

https://docs.docker.com/get-started/part3/

Docker Hubにレポジトリを作成

1) https://hub.docker.com/ にログイン

2) 上部メニューの[Repositories] より [Create Repository] をクリック

3) Create Repositoryの画面が開いたら、Name欄に「bulletinboard」と入力し [Create] ボタンをクリック

Docker Hubへのプッシュ

1) Docker Quickstart TerminalでDocker Hubにログインしておく

2) 以下コマンドを実行
user@DESKTOP-G1NPCN1 MINGW64 /d/Program Files/Docker Toolbox/node-bulletin-board/bulletin-board-app (master)
$ docker tag bulletinboard:1.0 xxxxxxxx/bulletinboard:1.0

$ docker push xxxxxxxx/bulletinboard:1.0
The push refers to repository [docker.io/xxxxxxxx/bulletinboard]
 :
user@DESKTOP-G1NPCN1 MINGW64 /d/Program Files/Docker Toolbox/node-bulletin-board/bulletin-board-app (master)
$
※ xxxxxxxx はDocker ID



技術メモ, Docker

その他の記事