我正在远程主机上运行dockerized fiware-orion。我知道我已经分配了将近200GB的存储空间,但是我意识到docker正在消耗大量磁盘空间来转储不必要的文件。
因此,每隔几天我必须检查一次以确保我有足够的存储空间来使Orion正常运行。每当实体查询返回空值时,我就知道Docker已完全消耗了100%的存储空间。因此,我必须清理磁盘并重新启动服务。平均而言,它每周发生一次。
$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 187G 0 100% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 12K 1.4G 1% /dev/shm
tmpfs 1.4G 138M 1.3G 10% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/dm-16 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/a0f3c5ab84aa06d5b2db00c4324dd6bf7141500ff4c83e23e9aba7c7268bcad4
tmpfs 285M 0 285M 0% /run/user/0
/dev/dm-3 10G 526M 9.5G 6% /var/lib/docker/devicemapper/mnt/0ef509f0c144e458c0c2f9bdbf6941e11d292a032953d48fb316c90caa05f21a
shm 64M 0 64M 0% /var/lib/docker/containers/71eea4f1af5b284059599eb07cc2aa2d73bdeccc9885952f2062763c81528d8f/mounts/shm
/dev/dm-4 10G 99M 9.9G 1% /var/lib/docker/devicemapper/mnt/3e108b5c2f45bcfe8c5f7ad28e7f8510ee666d5b4cd728a4b899857750440f1b
shm 64M 0 64M 0% /var/lib/docker/containers/7e9c401ec8993d7f24870692f84926bf39e4673ec4f23e1d9a7b7147cbfdf9b7/mounts/shm
/dev/dm-2 10G 266M 9.8G 3% /var/lib/docker/devicemapper/mnt/4d1e151d4270c38e96103713ddc9a3fc00b4e9411ddd89e3791c319508f12449
shm 64M 8.0K 64M 1% /var/lib/docker/containers/b6138e616e81c3e731499fc14793786fe60f334c6281f8116e8029d1cf561b6a/mounts/shm
/dev/dm-5 10G 325M 9.7G 4% /var/lib/docker/devicemapper/mnt/e1c6b5e20fed47cf38fb287ec424dac4a5c65c660b40de68fd604360e09082e4
shm 64M 0 64M 0% /var/lib/docker/containers/634ca1304587c7ad37b763512e7feece81e197a1229e4176213a9b70bb2984d0/mounts/shm
/dev/dm-6 10G 10G 20K 100% /var/lib/docker/devicemapper/mnt/38fc5fa4880f505e58067e90674e1c560378a75c9cc993dd6a673d1dd674fdff
shm 64M 0 64M 0% /var/lib/docker/containers/3a10f4a0e3123f7877a10f933d0d18df86b85b16b449457505f59e83d3e22192/mounts/shm
/dev/dm-8 10G 803M 9.3G 8% /var/lib/docker/devicemapper/mnt/456c4aa19f3ad57d3e7abc4a69e972371cfec2b67faeee4e548f18b2affe42f8
shm 64M 0 64M 0% /var/lib/docker/containers/e8964627c7b008829d4745c46d0210fe97d54f36693085145184243e17adba91/mounts/shm
/dev/dm-7 10G 1.2G 8.9G 12% /var/lib/docker/devicemapper/mnt/39e19f7dc51ed511d887932e13903129d1a3f13a6aee6c0e69c8e9e63dacfa6c
shm 64M 0 64M 0% /var/lib/docker/containers/1c2e3b465890a5cd010ab73bfc7f73c992e9abb49043357dc4916adeb74c8bed/mounts/shm
/dev/dm-10 10G 146M 9.9G 2% /var/lib/docker/devicemapper/mnt/5913150a306d91b81d12cd5f759aeb1cd6a192ca7dcaffbd8581d4e8735cc2d1
shm 64M 0 64M 0% /var/lib/docker/containers/6414fa2c750fcb723c836772d112589a67dff7ee636aa8e03c78e288b5d77ae5/mounts/shm
/dev/dm-11 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/2e557f90bc0dcc7e6f85a7536b2b480ae1bd61dcaf778f3fa3a0db5f93503fcf
shm 64M 0 64M 0% /var/lib/docker/containers/e9857010411222e00b1c990fdd15d61aa03576e9fe4b7829c98e140a33572dc2/mounts/shm
/dev/dm-9 10G 276M 9.8G 3% /var/lib/docker/devicemapper/mnt/a57a351c9bfd8a30db66a7666ab940690a4c7431b26e6771c8bd381097d179a4
shm 64M 0 64M 0% /var/lib/docker/containers/dcab63511f6bbd121213ed1fd667547c0339f70568d64747b5c280185951c510/mounts/shm
磁盘清理:
$docker volume ls -qf dangling=true | xargs docker volume rm 2>&1 | cat;
0a72c1d34b80bae0d14fbfd2c2fcf6fc85225c91a68a9c2f2ddcc638d019222e
0d2dd091a7a95dd939a7563f1529cde23567370ae0cc26c7cc7a83be6e288559
0e6c34eced17c7caf0c4972ab4541de315e8894234373643a633fde866c6a8e5
0e048ac11dcc838dc8eae4ce0bb33d5d24196a55a9d25ec74f2146e6c43cb021
0e70f251dfde36c48682fa031bdadbb54e5c8b2e2721efb4953111f1df103825
0f3d5dee1af5f69de58978a463a7215463556a34dfbb66a495a8dbf0feff2143
0f9c3f1d8c22fe5569eae4642c53f75ed79178f6233d2783a321cfeb396de9a9
1a83079ea34fa69cb31d68634ab453afb7c38407782185bd0800c4b63b61372e
1abac004cb400cf115a642b4008947d7fbb680ceb1bde951fc1ecac830553325
1b1bdd6311c6e49190e88232eca570d5ce77b0b81e6c20acd4a0f144f35e8ba0
1b90f899753f729e8f6e9317b023bc2b7bfa3445eb4ca05d40da9462f21cf122
1b332a0c0ea724fc9c10d8686641000762de479540074160f8d60dd947fb2e6a
1bb70a93caeb9bd106536d7add316d8771e1362d40fa00e5888f59711435bc4f
1d4712cb10539a47d344fdd711d9b905f01e44dbb47b2f7e2b0210a385311393
1e1a194980567c64108fbfd2214602690e30df23595fee8dbdcb1d5fedea961d
1f47735dbeb3f6608d7e506b687f36f884848d0f7c253768c9d97108c1f81c8d
2a194cb16e57845fff9f20118bbcd7f482878bbb3572f2aac45b07470a4e60e5
2acaeef75b19885c0163ec426fe4adb613267b60000021b596db1fafb9d98a16
2aff76459463fd4aa6940558ac18cc169f66ce70e682ccd4ce8758e62f98cbe0
2ba3c5dc2357aeaa54b1dbb1e923fce8109d57fed0f4e5f8798632751672e403
2c7cfce56be947e574b28b1d434cdbdecbebc6b2f0fc3d1c22a869b4e92d0ee7
2d566a5614991a077f3b010a70736f42e6d04e825646b9d3c509c759f8f37766
2e10db3cb23b09c8d895f01c90054538427cc6399872899d1c8d2bb4ef43711f
2e2801a798e33ed3cfd5f0f6c5fc43253150ac0ac8d19494114b2b9004f65d1c
2f82f3ab86a609e67286666e75f1a43496842d0708b7aea36ec40a2cd533f117
2f79104fb3c570b228b781ce0b23f790f685bb8d452aa734c52425586484cae2
3a7fff8d67681e6a701b61c14e74cdcf77fdfb830cfa31ed156865aef57df07d
3a5723321d452c33e35d3002193398e2a7a10890bd4adbe6593231633e649bf3
3aa1fd9bad1b75e09e13741ace2c9ff5cd8a630cfc49124fbcab85aa5b943222
.
.
.
磁盘空间(清理磁盘后):
$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 38G 150G 20% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs 1.4G 137M 1.3G 10% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/dm-16 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/a0f3c5ab84aa06d5b2db00c4324dd6bf7141500ff4c83e23e9aba7c7268bcad4
tmpfs 285M 0 285M 0% /run/user/0
/dev/dm-11 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/2e557f90bc0dcc7e6f85a7536b2b480ae1bd61dcaf778f3fa3a0db5f93503fcf
shm 64M 0 64M 0% /var/lib/docker/containers/e9857010411222e00b1c990fdd15d61aa03576e9fe4b7829c98e140a33572dc2/mounts/shm
磁盘空间(一小时后):
$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 39G 149G 21% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 12K 1.4G 1% /dev/shm
tmpfs 1.4G 138M 1.3G 10% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/dm-16 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/a0f3c5ab84aa06d5b2db00c4324dd6bf7141500ff4c83e23e9aba7c7268bcad4
tmpfs 285M 0 285M 0% /run/user/0
/dev/dm-11 10G 49M 10G 1% /var/lib/docker/devicemapper/mnt/2e557f90bc0dcc7e6f85a7536b2b480ae1bd61dcaf778f3fa3a0db5f93503fcf
shm 64M 0 64M 0% /var/lib/docker/containers/e9857010411222e00b1c990fdd15d61aa03576e9fe4b7829c98e140a33572dc2/mounts/shm
/dev/dm-2 10G 99M 9.9G 1% /var/lib/docker/devicemapper/mnt/735a5508654bfdb6c0752838c5ab65ff7bf1b82a7329ea20ee215651a5ae39e2
shm 64M 0 64M 0% /var/lib/docker/containers/95dd176c4df52b02fc8b8a78ebdbab444a7be1213a2cfc54beee134f450bad23/mounts/shm
/dev/dm-4 10G 526M 9.5G 6% /var/lib/docker/devicemapper/mnt/1a749000c102efd084e52034a44cec2e8524ccdb75bcb27972f2f05dcf083ea8
shm 64M 0 64M 0% /var/lib/docker/containers/a8178e76fb4107f90fe1187698d58e362969515343b0adf7c428436fe9d482cb/mounts/shm
/dev/dm-1 10G 383M 9.7G 4% /var/lib/docker/devicemapper/mnt/1dc589a616892704fd55587a7d558307db703155a4fd743219addc7b5a65d962
/dev/dm-3 10G 266M 9.8G 3% /var/lib/docker/devicemapper/mnt/7a501e67c52c5d2dbd77fd29cc68946469c3a609c2fe356b7bba7fde82f148a1
shm 64M 0 64M 0% /var/lib/docker/containers/495918e5611c7a416ef20401f5701e1570b94f540eb5d764c47c6a74f73a169f/mounts/shm
shm 64M 8.0K 64M 1% /var/lib/docker/containers/374f9bb469ec5fe42b7e7772a5d4c580aa36178f64efac8b3fba02f148b42de6/mounts/shm
/dev/dm-6 10G 502M 9.6G 5% /var/lib/docker/devicemapper/mnt/b58cbb82569f79848c432dae10c8e549ac2e783e1ba065def8a033cf94a625c8
shm 64M 0 64M 0% /var/lib/docker/containers/98dd55e27406e756b870361e0e25cc7cca4f57a9e95161aa8a3359a13a477e58/mounts/shm
/dev/dm-7 10G 325M 9.7G 4% /var/lib/docker/devicemapper/mnt/cfcfd404d2fa0e0fc770d34e1b6b0cd27bbef84390bfad02368760c4da2abe87
shm 64M 0 64M 0% /var/lib/docker/containers/a1bb4f9e726902446809a85d17553b93f773d8013e227faa0a254d90f1821359/mounts/shm
/dev/dm-9 10G 1.2G 8.9G 12% /var/lib/docker/devicemapper/mnt/1529c11ac704d149b94723287a390dd38d9373c58ed5ed0b21d8d0585a0a7ac7
shm 64M 0 64M 0% /var/lib/docker/containers/8594cfcef1fe0cf3fa75bac83ce5ef18ef096cad6debe0957384fc424f3edc03/mounts/shm
/dev/dm-5 10G 276M 9.8G 3% /var/lib/docker/devicemapper/mnt/88b94454d368ae2066fde71dd0062252b09fb87c8e4a3c8fda351013ea7a7182
shm 64M 0 64M 0% /var/lib/docker/containers/e1900109937266b65090c366c60a70581c0584474346083c8a9b971831b3edaf/mounts/shm
/dev/dm-10 10G 803M 9.3G 8% /var/lib/docker/devicemapper/mnt/9a84f16db1fe54d4d0d6719ab1a48c6d88d53880c65345c010bf8fc4164166d6
shm 64M 0 64M 0% /var/lib/docker/containers/10db801e75d33f20f07954848ad2c8c3a4213d59c0046469c8a773fb1e0f172a/mounts/shm
/dev/dm-8 10G 146M 9.9G 2% /var/lib/docker/devicemapper/mnt/dd643159c8d53030e6f9bac07353fabb4d279015b7f565c2f05fd60b074109d1
shm 64M 0 64M 0% /var/lib/docker/containers/47ac2d9eb4beeddc4908ceb2c415abf9311cd4eac8d40825049c7965fd8644e4/mounts/shm
有没有办法避免这个问题?我知道这完全是docker问题,但是添加了fiware-orion标签,因此,如果有人有类似的经验。
编辑:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
fiware/wirecloud latest 57588c317927 3 months ago 1.06GB
grafana/grafana latest ffd9c905f698 3 months ago 241MB
postgres 10 3e016ba4a307 3 months ago 230MB
memcached 1 b26493421cee 3 months ago 62.1MB
telefonicaiot/lightweightm2m-iotagent latest 8788b0f0e1e7 3 months ago 243MB
fiware/orion latest 4f5e794be6d8 4 months ago 271MB
fiware/cygnus-ngsi latest 1ecc85e54361 4 months ago 806MB
nginx latest f09fe80eb0e7 4 months ago 109MB
mongo 3.6 2d6f175a24cf 4 months ago 361MB
elasticsearch 2.4 5e9d896dc62c 9 months ago 479MB
jbergknoff/postgresql-client latest 23850b2852a4 15 months ago 11.5MB
正在运行的容器:
$docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------------
fiware-cygnus /cygnus-entrypoint.sh Up (healthy) 0.0.0.0:5050->5050/tcp, 0.0.0.0:5080->5080/tcp
fiware-elasticsearch /docker-entrypoint.sh elas ... Up 9200/tcp, 9300/tcp
fiware-grafana /run.sh Up 0.0.0.0:53153->3000/tcp
fiware-iotagent pm2-runtime bin/lwm2mAgent ... Up (healthy) 0.0.0.0:4041->4041/tcp, 5684/tcp, 0.0.0.0:5684->5684/udp
fiware-memcached docker-entrypoint.sh memca ... Up 11211/tcp
fiware-mongo docker-entrypoint.sh --bin ... Up 0.0.0.0:27017->27017/tcp
fiware-nginx nginx -g daemon off; Up 0.0.0.0:53152->53152/tcp, 80/tcp
fiware-orion /usr/bin/contextBroker -fg ... Up (healthy) 0.0.0.0:1026->1026/tcp
fiware-postgres docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
fiware-wirecloud /docker-entrypoint.sh Up (healthy) 8000/tcp
docker-compose文件:
version: "3.1"
services:
mongo:
image: mongo:3.6
hostname: mongo
container_name: fiware-mongo
ports:
- "27017:27017"
networks:
- default
command: --bind_ip_all --smallfiles
# volumes:
# - mongo-db:/data
orion:
image: fiware/orion
hostname: orion
container_name: fiware-orion
depends_on:
- mongo
networks:
- default
ports:
- "1026:1026"
expose:
- "1026"
command: -dbhost mongo -logLevel DEBUG
healthcheck:
test: curl --fail -s http://localhost:1026/version || exit 1
lightweightm2m-iotagent:
image: telefonicaiot/lightweightm2m-iotagent
hostname: idas
container_name: fiware-iotagent
depends_on:
- mongo
networks:
- default
expose:
- "4041"
- "5684"
ports:
- "4041:4041"
- "5684:5684/udp"
environment:
- "IOTA_CB_HOST=orion"
- "IOTA_CB_PORT=1026"
- "IOTA_NORTH_PORT=4041"
- "IOTA_REGISTRY_TYPE=mongodb"
- "IOTA_LOG_LEVEL=DEBUG"
- "IOTA_TIMESTAMP=true"
- "IOTA_MONGO_HOST=mongo"
- "IOTA_MONGO_PORT=27017"
- "IOTA_MONGO_DB=lwm2miotagent"
- "IOTA_HTTP_PORT=5684"
- "IOTA_PROVIDER_URL=http://lightweightm2m-iotagent:4041"
- "IOTA_AUTOCAST=true"
- "IOTA_CB_NGSI_VERSION=v2"
healthcheck:
test: curl --fail -s http://localhost:4041/iot/about || exit 1
comment
cygnus:
image: fiware/cygnus-ngsi:latest
hostname: cygnus
container_name: fiware-cygnus
depends_on:
- postgres
networks:
- default
expose:
- "5080"
ports:
- "5050:5050"
- "5080:5080"
environment:
- "CYGNUS_POSTGRESQL_HOST=postgres"
- "CYGNUS_POSTGRESQL_PORT=5432"
- "CYGNUS_POSTGRESQL_USER=postgres"
- "CYGNUS_POSTGRESQL_PASS=password"
- "CYGNUS_LOG_LEVEL_=DEBUG"
- "CYGNUS_SERVICE_PORT=5050"
- "CYGNUS_API_PORT=5080"
- "CYGNUS_POSTGRESQL_ENABLE_CACHE=true"
healthcheck:
test: curl --fail -s http://localhost:5080/v1/version || exit 1
nginx:
restart: always
container_name: fiware-nginx
image: nginx
networks:
- default
ports:
- "53152:53152"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./wirecloud-static:/var/www/static:ro
- ./nginx_logs:/var/log/nginx
depends_on:
- wirecloud
postgres:
restart: always
image: postgres:10
hostname: postgres
container_name: fiware-postgres
expose:
- "5432"
ports:
- "5432:5432"
networks:
- default
environment:
- "POSTGRES_PASSWORD=password"
- "POSTGRES_USER=postgres"
- "POSTGRES_DB=postgres"
volumes:
- ./postgres-data:/var/lib/postgresql/data
grafana:
restart: always
image: grafana/grafana
container_name: fiware-grafana
depends_on:
- postgres
ports:
- "53153:3000"
environment:
- plugins="crate-datasource,grafana-clock-panel,grafana-worldmap-panel"
volumes:
- ./grafana:/var/lib/grafana:rw
elasticsearch:
restart: always
container_name: fiware-elasticsearch
image: elasticsearch:2.4
volumes:
- ./elasticsearch-data:/usr/share/elasticsearch/data
command: elasticsearch -Des.index.max_result_window=50000
memcached:
restart: always
container_name: fiware-memcached
image: memcached:1
command: memcached -m 2048m
wirecloud:
restart: always
image: fiware/wirecloud
container_name: fiware-wirecloud
depends_on:
- postgres
- elasticsearch
- memcached
environment:
- DEBUG=False
# - DEFAULT_THEME=wirecloud.defaulttheme
- DB_HOST=postgres
- DB_PASSWORD=password # Change this password!
- FORWARDED_ALLOW_IPS=*
- ELASTICSEARCH2_URL=http://elasticsearch:9200/
- MEMCACHED_LOCATION=memcached:11211
# Uncomment the following environment variables to enable IDM integration
#- FIWARE_IDM_SERVER=${FIWARE_IDM_SERVER}
#- SOCIAL_AUTH_FIWARE_KEY=${SOCIAL_AUTH_FIWARE_KEY}
#- SOCIAL_AUTH_FIWARE_SECRET=${SOCIAL_AUTH_FIWARE_SECRET}
volumes:
- ./wirecloud-data:/opt/wirecloud_instance/data
- ./wirecloud-static:/var/www/static
#- ./settings.py:/opt/wirecloud_instance/wirecloud_instance/settings.py:ro
答案 0 :(得分:1)
使用crontab安排docker system prune -f
从Docker引擎中删除悬空的卷(即没有关联运行容器的卷),映像和容器。
https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
如果您不了解crontab的语法,this可能会有所帮助。
修改
*/5 * * * * docker system prune -f > /dev/null
例如,这每隔5分钟在服务器上运行一次清理。
更新
我发现了一个有趣的命令,该命令针对特定的卷显示附加了哪些容器:
https://github.com/moby/moby/issues/31436#issuecomment-283190953
对确定悬空的元凶可能有用。