Docker run 的 container 內的 root 只是一般使用者, 必須要給予真正的 root 權限, 才能執行 mount 或是在 docker 中啟動 docker.
主要原因
CentOS 7 權限不足的原因
解決辦法
docker run --name centos --privileged -d centos:latest /sbin/init
給予真正的 root 的權限
docker run --name centos --privileged -d centos:latest /sbin/init
建立 3 個 Cassandra Server 的 Cluster
docker pull 取得最新的 cassandra image
$ docker pull cassandra:latest
NBAS055de-MacBook-Pro:~ nbas055$ docker pull cassandra:latest
latest: Pulling from library/cassandra
9f0706ba7422: Pull complete
47bacf36113f: Pull complete
7c6842ab2e6f: Pull complete
b0970d2724fb: Pull complete
7dd1392a6ce5: Pull complete
43faf38e08a8: Pull complete
448a3a082d57: Pull complete
2c7ffe4dc3db: Pull complete
caac33302fe6: Pull complete
8ba01779bed9: Pull complete
1aa363d655b1: Pull complete
02a5c66a8b99: Pull complete
Digest: sha256:b25a30a85b5869257f560fb05296886136b809288f53f32ebefde8967e6e6ca5
Status: Downloaded newer image for cassandra:latest
docker images 查看所以已下載的 images
$ docker images
NBAS055de-MacBook-Pro:~ nbas055$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cassandra latest c82d9de5d478 5 days ago 386MB
docker network create 建立一個 bridge 類型的網路
$ docker network create --driver bridge apptier
NBAS055de-MacBook-Pro:~ nbas055$ docker network create --driver bridge apptier
c40c7ae8e9a1c6ad8eced493c0fa77d881cd63bc2c2a702af666d6cc4b1dcb96
docker network ls 查看目前所有網路設定
$ docker network ls
NBAS055de-MacBook-Pro:~ nbas055$ docker network ls
NETWORK ID NAME DRIVER SCOPE
c40c7ae8e9a1 apptier bridge local
de34dc3841de bridge bridge local
fcde3e725906 host host local
e70d8c2c4afd none null local
docker run: 建立 cassandra server 的 container
--name cassanda1: 設定 container 名稱為 cassandra1
--network apptier: 設定 network 為 apptier
-d cassandra: 背景執行 cassandra image
$ docker run --name cassandra --network apptier -d cassandra
NBAS055de-MacBook-Pro:~ nbas055$ docker run --name cassandra1 --network apptier -d cassandra
33b7a234cef63f07ec62366aaf86035fa4552157a5cdf8645438a64975fbf056
NBAS055de-MacBook-Pro:~ nbas055$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33b7a234cef6 cassandra "/docker-entrypoin..." 3 seconds ago Up 2 seconds 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra1
docker ps 列出目前正在執行的 containers
$ docker ps
NBAS055de-MacBook-Pro:~ nbas055$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f22277bf144 cassandra "/docker-entrypoin..." 2 seconds ago Up 1 second 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra1
docker stats 查看所有 container 執行的狀況
$ docker stats
NBAS055de-MacBook-Pro:~ nbas055$ docker stats
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
33b7a234cef6 0.10% 1.148GiB / 1.952GiB 58.83% 1.12kB / 0B 0B / 1.78MB 42
若 container 設定錯誤docker rm cassandra1: 指定刪除 cassandra1 的 container
-f: 強制刪除P.S. 刪除之後再嘗試建立一個 container
$ docker rm -f cassandra1
NBAS055de-MacBook-Pro:~ nbas055$ docker rm -f cassandra1
33b7a234cef6
NBAS055de-MacBook-Pro:~ nbas055$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
設定 cassandra2 跟 cassandra3
執行 docker run 同時指定連結目標
-e CASSANDRA_SEEDS: 設定目標為 cassandra1
$ docker run --name cassandra2 --network apptier -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.Networks.apptier.IPAddress }}' cassandra1)" -d cassandra
$ docker run --name cassandra3 --network apptier -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.Networks.apptier.IPAddress }}' cassandra1)" -d cassandra
NBAS055de-MacBook-Pro:~ nbas055$ docker run --name cassandra2 --network apptier -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.Networks.apptier.IPAddress }}' cassandra1)" -d cassandra
cf300680fa79787482da750fb7b7907c01b263889ca2e17434b9a829f56e3346
NBAS055de-MacBook-Pro:~ nbas055$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf300680fa79 cassandra "/docker-entrypoin..." 12 seconds ago Up 10 seconds 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra2
7f22277bf144 cassandra "/docker-entrypoin..." 45 minutes ago Up 44 minutes 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra1
NBAS055de-MacBook-Pro:~ nbas055$ docker run --name cassandra3 --network apptier -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.Networks.apptier.IPAddress }}' cassandra1)" -d cassandra
1b3070561d24662830117005ace7615ccab8e66d652b0c5401f852da93490160
NBAS055de-MacBook-Pro:~ nbas055$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b3070561d24 cassandra "/docker-entrypoin..." About a minute ago Up About a minute 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra3
a277482c88c3 cassandra "/docker-entrypoin..." 3 minutes ago Up 3 minutes 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra2
fbc7888155bc cassandra "/docker-entrypoin..." 4 minutes ago Up 4 minutes 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra1
NBAS055de-MacBook-Pro:~ nbas055$ docker stats
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1b3070561d24 223.78% 2.131GiB / 7.787GiB 27.36% 578B / 0B 0B / 692kB 41
a277482c88c3 0.58% 2.137GiB / 7.787GiB 27.45% 1.13kB / 0B 0B / 1.95MB 42
fbc7888155bc 0.45% 2.14GiB / 7.787GiB 27.48% 1.91kB / 0B 76MB / 1.95MB 42
docker exec -it 進入 cassandra1
nodetool status 查看 cassandra node server 運行狀態
$ docker exec -it cassandra1 /bin/bash
$ nodetool status
NBAS055de-MacBook-Pro:~ nbas055$ docker exec -it cassandra1 /bin/bash
root@687e14268025:/# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.18.0.2 108.67 KiB 256 61.8% 791e7d85-9b08-45e0-8804-c804a3538679 rack1
UN 172.18.0.3 103.21 KiB 256 67.9% ecbe769c-0d54-4d4b-8019-7f5bfa51a7ed rack1
UN 172.18.0.4 15.35 KiB 256 70.4% 634eb8c4-17ea-40dd-ac2e-33ab97ada0ef rack1