Docker operation memo
usage environment
VirtulBox : 6.1
Host OS: Ubuntu 18.04
Docer : docker-ce 19.03.13
- The host OS of docker is a virtual environment running on VirtualBox.
Image execution
When booting CentOS with privileges.
$ sudo docker run -itd --privileged --name PROCESS_NAME IMAGE_NAME /sbin/init
$ sudo docker run -itd --privileged -p 8080:80 --name PROCESS_NAME IMAGE_NAME /sbin/init
↑ When specifying the port, it looks like this
- Sudo is not required if the user to be executed is included in the docker group.
Checking the status of the container
Stream
$ sudo docker stats centos8
Do not stream
$ sudo docker stats centos8 --no-stream
Set memory limit after booting
I stumbled in various ways, but succeeded by doing the following.
$ sudo docker update -m 1G --memory-swap -1 CONTAINER_ID
The following things such as stumbling
At first, I executed the following command, but an error occurred.
$ sudo docker update -m 1G CONTAINER_ID
Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
Solved by changing the swap setting of grub.
$ sudo vi /etc/default/grub
$ sudo update-grub
grub.Update cfg and restart the host OS.
When I re-executed it after restarting, the following error occurred.
$ docker update -m 1G 917f3986a06b
Error response from daemon: Cannot update container 917f3986a06bb9f99b095af4f3e5334ce125f596f9926db2733bdb4d20868b47: Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time
So, I set the “–memory-swap -1” option and executed it, and it succeeded.
When the memory is loaded as shown below, it can be confirmed that the 1G limit is applied.
$ docker exec -it centos8 /bin/bash
# /dev/null < `yes`
$ docker stats centos8 --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
917f3986a06b centos8 106.50% 1GiB / 1GiB 100.00% 15.4kB / 10.4kB 52.3MB / 4.1kB 229