Docker内置命令:
# 查看容器资源使用情况
docker stats [容器名/ID]
# 查看容器详细信息
docker inspect [容器名/ID]
a. Sysbench (综合性能测试)
# 在容器内安装
docker exec -it [容器名] apt-get update && apt-get install -y sysbench
# CPU测试
sysbench cpu --cpu-max-prime=20000 run
# 内存测试
sysbench memory --memory-block-size=1K --memory-total-size=100G run
b. Stress (压力测试)
# 启动压力测试容器
docker run --rm -it progrium/stress --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 60s
c. JMeter (Web应用测试)
# 运行JMeter容器
docker run --rm -v $(pwd):/tests -w /tests justb4/jmeter -n -t test_plan.jmx -l test_result.jtl
iperf3:
# 服务端容器
docker run -it --rm --name=iperf3-server networkstatic/iperf3 -s
# 客户端容器
docker run -it --rm networkstatic/iperf3 -c [server-ip]
fio:
docker run --rm -v /path/to/test:/test ljishen/fio \
fio --name=test --directory=/test --ioengine=libaio --rw=randread \
--bs=4k --numjobs=16 --size=1G --runtime=60 --time_based --group_reporting
cAdvisor:
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
gcr.io/cadvisor/cadvisor:v0.47.0
访问 http://localhost:8080
查看监控数据
--cpus
, --memory
等参数限制容器资源通过以上工具和方法,您可以全面评估Docker容器在不同负载下的性能表现。