Docker 設定
Links
Containers
docker run -d --restart=always \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup
version: '3'
services:
netdata:
image: netdata/netdata
container_name: netdata
hostname: example.com # set to fqdn of host
ports:
- 19999:19999
restart: unless-stopped
cap_add:
- SYS_PTRACE
security_opt:
- apparmor:unconfined
volumes:
- netdataconfig:/etc/netdata
- netdatalib:/var/lib/netdata
- netdatacache:/var/cache/netdata
- /etc/passwd:/host/etc/passwd:ro
- /etc/group:/host/etc/group:ro
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /etc/os-release:/host/etc/os-release:ro
environment:
- NETDATA_CLAIM_TOKEN=ygmlGGb7aw_jhOpQ9RZgpmaDxzdWN-VRPufAjCnrq_MY_IO28jzcEWjScrmaxyKef7zSbS5EM3MdrrOlo0CU4Vy0Z1HGUD3OiOpQ1FwKwOZYj-ENpEA7YEykadmuzS3z-LuHoOg
- NETDATA_CLAIM_URL=https://app.netdata.cloud
- NETDATA_CLAIM_ROOMS=
volumes:
netdataconfig:
netdatalib:
netdatacache:
Linux Install
# 更新apt套件資訊
sudo apt update
# 安裝必要套件
sudo apt-get -y install ca-certificates curl gnupg lsb-release # 新增Docker官方GPG
curl -fsSL [Index of linux/ubuntu/](https://download.docker.com/linux/ubuntu)/gpg | sudo apt-key add -
# 指定版本
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # 再次更新apt套件資訊
sudo apt update
# 安裝Docker
sudo apt install -y docker-ce docker-ce-cli containerd.io
# 測試Docker hello world
sudo docker run hello-world
# 新增Docker 群組
sudo groupadd docker
# 將使用者添加到Docker群組中 sudo usermod -aG docker $USER # 重新登入
newgrp docker
# 測試
docker run hello-world
# compose build
docker-compose up -d
# rebuild
docker-compose up -d --no-deps --build <service_name>
# execute command to specific container
docker exec -it shlink shlink api-key:generate
docker exec -it short-url:import csv
Commands
# 顯示Container
docker ps
# 顯示Images
docker images
# 顯示Container輸出
docker logs -f container_id
# 進入container並使用bash作為shell
docker exec -it container_id bash
# 停止/啟動/重啟container
docker stop/start/restart container_id
# Stop by name
docker container stop $(docker container ls -q --filter name="abc*")
# 刪除Container
docker rm -f container_id
#強制刪除所有Container
docker rm -vf $(docker ps -a -q)
# 刪除Image
docker rmi -f image_id
# 強制刪除所有Image
docker rmi -f $(docker images -a -q)
# To remove all images which are not used by existing containers, use the -a flag:
docker image prune -a