LoginSignup
0
1

More than 3 years have passed since last update.

Docker 操作メモ

Last updated at Posted at 2020-10-14

使用環境

VirtulBox : 6.1
ホスト OS :Ubuntu 18.04
Docer : docker-ce 19.03.13
※ docker のホスト OS は VirtualBox 上で動かしている仮想環境

イメージの実行

CentOS を特権を付けて起動する場合。

$ sudo docker run -itd --privileged --name PROCESS_NAME IMAGE_NAME /sbin/init
$ sudo docker run -itd --privileged -p 8080:80 --name PROCESS_NAME IMAGE_NAME /sbin/init
                                       ↑ポートを指定する場合はこんな感じ

※docker グループに実行するユーザを入れていれば sudo は必要ない。

コンテナのステータス確認

ストリームさせる

$ sudo docker stats centos8

ストリームさせない

$ sudo docker stats centos8 --no-stream

起動した後でメモリリミットを設定する

いろいろ躓いたが以下を実行することで成功。

$ sudo docker update -m 1G --memory-swap -1 CONTAINER_ID

以下躓いたことなど

初めは以下のコマンドを実行したがエラーとなってしまった。

$ sudo docker update -m 1G CONTAINER_ID
Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.

grub の swap 設定を変更することで解決。

$ sudo vi /etc/default/grub
$ sudo update-grub
grub.cfg をアップデートしてホスト OS を再起動。

再起動後に再度実行したところ以下のエラーとなった。

$ docker update -m 1G 917f3986a06b
Error response from daemon: Cannot update container 917f3986a06bb9f99b095af4f3e5334ce125f596f9926db2733bdb4d20868b47: Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time

そこで、「--memory-swap -1」オプションを設定し実行したところ成功。

以下のようにメモリに負荷をかけたところ 1G の制限が掛かっていることが確認できる。

$ docker exec -it centos8 /bin/bash
# /dev/null < `yes`
$ docker stats centos8 --no-stream
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
917f3986a06b        centos8             106.50%             1GiB / 1GiB         100.00%             15.4kB / 10.4kB     52.3MB / 4.1kB      229
0
1
0

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
0
1