Introduction#
- understand memory
- understand cpu-shares
- understand cpu-period and cpu-quota
- pressure test
Hello Container#
docker container run --name hello IMAGE /bin/sh -c "while true; do echo 1; sleep 2; done;"
Over write entrypoing and CMD
docker run -it --entrypoint '/bin/sh' book-app:latest -c "while true; do echo 1; sleep 2; done;"
Run busy box
docker run -it --entrypoint '/bin/sh' public.ecr.aws/docker/library/busybox:uclibc -c "while true; do echo 1; sleep 2; done;"
Or
docker run -it --entrypoint '/bin/sh' public.ecr.aws/docker/library/busybox:uclibc -c "while true; do echo 1 >> /tmp/hello; sleep 2; done;"
Docker exec into a running container
docker exec -it b15ac4043449 /bin/sh
CPU Request and Limits#
experiment 1: understand cpu-shares
- cpu-shares set the relative cpu usage between containers
- it is enforced only when CPU cycles are constrained
- when plenty of CPU cycles, all containers use as much CPU as they need
get imageId
sudo docker images
run some containers
sudo docker run -p 80:8080 --cpu-shares 1024 --name cpu-1 $imageIdsudo docker run -p 81:8080 --cpu-shares 2048 --name cpu-2 $imageId
then run the pressure test, it is epxected that
- cpu-2 uses CPU twice time cpu-1
- however, this only happen when there is CPU cycles constrained
- so, normaly we still see they use the same CPU usage
experiment 2: understand cpu-quota and cpu-period
sudo docker run -p 80:8080 --cpu-shares 1024 --cpu-period=100000 --cpu-quota=1000 --name cpu-1 $imageIdsudo docker run -p 81:8080 --cpu-shares 2048 --cpu-period=100000 --cpu-quota=2000 --name cpu-2 $imageIdsudo docker run -p 81:8080 --cpu-shares 2048 --cpu-period=100000 --cpu-quota=10000 --name cpu-3 $imageId
then do the pressure test
- at most, cpu-1 can use 1 percent of CPU cycles
- at most, cpu-2 can use 2 percent of CPU cycles
- at most, cpu-3 can use 10 percent of CPU cycles
Pressure Test#
while truedo# curl -s http://127.0.0.1:80 > /dev/nullcurl -s http://127.0.0.1:81 > /dev/null# curl -s http://127.0.0.1:82 > /dev/nulldone;