kevin@hostos1:~$ docker run -it --name=add-net ubuntu:14.04 bash
kevin@hostos1:~$ docker ps
kevin@hostos1:~$ docker network create --driver=bridge web-network
kevin@hostos1:~$ docker network connect web-network add-net
kevin@hostos1:~$ docker exec add-net route
root@10db94219c83:/# ifconfig
컨테이너에 자원 할당 ▶ 기본값 unlimit으로 설정되어 있음
kevin@hostos1:~$ grep -c processor /proc/cpuinfo
4
kevin@hostos1:~$ htop
cpu 할당 전 cpu register에 작업을 등록한 후 프로세스에게 cpu 사용 시간을 할당
▶ cpu 자원 소비 시간 제한 가능
부하 유발 기능 ▶ cpu 자원 소비 비율 제한 가능
cpu에 과부하 적용
kevin@hostos1:~$ stress -c 1 -t 10s
--device-read-bps, -device-write-bps
--device-read-iops, -device-write-iops
Linux 5.15.0-46-generic (hostos1) 2022년 09월 15일 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.37 0.01 0.42 0.05 0.00 99.15
Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
loop0 0.00 0.00 0.00 362 0
loop1 0.00 0.02 0.00 1153 0
loop2 0.00 0.02 0.00 1375 0
loop3 0.01 0.30 0.00 22764 0
loop4 0.00 0.00 0.00 17 0
loop5 0.00 0.00 0.00 359 0
loop6 0.01 0.51 0.00 38467 0
loop7 0.00 0.04 0.00 2732 0
loop8 0.00 0.02 0.00 1341 0
loop9 0.00 0.00 0.00 50 0
sda 1.69 21.09 35.83 1575558 2677352
sdb 1.06 8.79 132.72 656500 9916188
scd0 0.00 0.00 0.00 2 0
kevin@hostos1:~$ docker run -d --name=cpuset1 --cpuset-cpus 2 leecloudo/stress:1.0 stress -c 1
kevin@hostos1:~$ docker run -d --name=cpuset2 --cpuset-cpus 0,3 leecloudo/stress:1.0 stress -c 2
kevin@hostos1:~$ docker run -d --name=cpuset1 --cpuset-cpus 2 leecloudo/stress:1.0 stress --cpu 1
kevin@hostos1:~$ docker update --cpus=0.2 cpuset1
kevin@hostos1:~$ docker update --cpus=0.6 cpuset1
kevin@hostos1:~$ docker run -d --name=cpuset2 --cpuset-cpus 0,3 leecloudo/stress:1.0 stress -c 2
kevin@hostos1:~$ docker update --cpus=0.2 cpuset2
▶ 합쳐서 20% 사용
kevin@hostos1:~$ docker run -d --name=nginx200m --memory=200m nginx:1.23.1-alpine
kevin@hostos1:~$ docker inspect nginx200m | grep -i memory
kevin@hostos1:~$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
209715200/1024/1024
200
quit
kevin@hostos1:~$ docker run -d --name=nginx200ms --memory=200m --memory-swap=200m nginx:1.23.1-alpine
kevin@hostos1:~$ docker inspect nginx200ms | grep -i memory
kevin@hostos1:~$ docker run -itd -m=4m --name=mydb mysql:5.7-debian
docker: Error response from daemon: Minimum memory limit allowed is 6MB.
See 'docker run --help'.
kevin@hostos1:~$ docker run -itd -m=6m --name=mydb mysql:5.7-debian
kevin@hostos1:~$ docker run -it --rm ubuntu:14.04 bash
root@1c7e80a2e8fe:/# dd if=/dev/zero of=test.out bs=1M count=10 oflag=direct
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0218984 s, 479 MB/s
kevin@hostos1:~$ docker run -it --rm --device-write-bps /dev/sdb:1mb ubuntu:14.04 bash
root@782bb618fe66:/# dd if=/dev/zero of=test.out bs=1M count=10 oflag=direct
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 10.1129 s, 1.0 MB/s
kevin@hostos1:~$ docker run -it --rm --device-write-bps /dev/sdb:10mb ubuntu:14.04 bash
root@3340c44c96c4:/# dd if=/dev/zero of=test.out bs=1M count=10 oflag=direct
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 1.13695 s, 9.2 MB/s
공유 설정 기능
1) bind mount
bind mount -v(--volume) 호스트절대경로:컨테이너절대경로
▶ -v /data/test1:mount1
2) volume
docker volume create volume_name
▶ -v volume_name:/mount2
3) tmpfs mount
임시 경로 설정 (잘 사용하지 않는다.)
[실습]
*.idb
데이터를 저장한 파일
[실습]
kevin@hostos1:~/hello1$ vi test1.txt
kevin@hostos1:~/hello1$ cat > test1.txt
test1 (ctrl + d)
kevin@hostos1:~$ docker run -it --name ubuntu_volume1 -v /home/kevin/hello1:/hello1 -v /home/kevin/hello2:/hello2 ubuntu:16.04 bash
root@e7bc5e35e16e:/# ls
bin dev hello1 home lib64 mnt proc run srv tmp var
boot etc hello2 lib media opt root sbin sys usr
root@e7bc5e35e16e:/# cd hello1
root@e7bc5e35e16e:/hello1# ls
test1.txt
root@e7bc5e35e16e:/hello1# cd ../hello2
root@e7bc5e35e16e:/hello2# ls
test2.txt
root@e7bc5e35e16e:/hello2# mount
root@e7bc5e35e16e:/hello2# cd ../hello1
root@e7bc5e35e16e:/hello1# echo "hi~" >> test1.txt
root@e7bc5e35e16e:/hello1# cat test1.txt
test1hi~
kevin@hostos1:~/hello1$ cat test1.txt
test1hi~
kevin@hostos1:~$ cd hello2
kevin@hostos1:~/hello2$ cat > test2.txt
test2kevin@hostos1:~/hello2$ cat test2.txt
test2kevin@hostos1:~/hello2$ vi test2.txt
kevin@hostos1:~/hello2$ cd ..
volume은 해당 컨테이너(application)의 주요 소스, 구성 경로에 배치(해당 경로에 데이터 파일 저장)하면 된다!
1) httpd -- volume --> /var/www/html
2) nginx -- volume --> /etc/nginx or /usr/share/nginx/html
Q) mysql:5.7-debian
---> stop/rm ---> mysql:8.0 yes
Q) mysql:5.7-debian
---> stop/rm ---> mariadb:10.2 no
확인해보자!
kevin@hostos1:/$ docker run -it --name=mydb-vol -e MYSQL_ROOT_PASSWORD=pass123# \
-e MYSQL_DATABASE=kakaodb -v /home/kevin/mydb:/var/lib/mysql mysql:5.7-debian
kevin@hostos1:~$ docker exec -it mydb-vol bash
root@dc5b2d563da8:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kakaodb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> use kakaodb;
Database changed
mysql> create table kakao_prod (prod_name varchar(20), prod_item varcha r(50));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into kakao_prod values ('imoticon', 'crong');
Query OK, 1 row affected (0.03 sec)
mysql> select * from kakao_prod;
+-----------+-----------+
| prod_name | prod_item |
+-----------+-----------+
| imoticon | crong |
+-----------+-----------+
1 row in set (0.00 sec)
mysql> exit
Bye
root@dc5b2d563da8:/# cd /var/lib/mysql/kakaodb/
root@dc5b2d563da8:/var/lib/mysql/kakaodb# ls
db.opt kakao_prod.frm kakao_prod.ibd
kevin@hostos1:~$ ls
mydb
kevin@hostos1:~$ cd mydb
kevin@hostos1:~/mydb$ sudo ls -l kakaodb/
[sudo] password for kevin:
total 112
-rw-r----- 1 systemd-coredump systemd-coredump 65 9월 15 13:54 db.o pt
-rw-r----- 1 systemd-coredump systemd-coredump 8610 9월 15 14:05 kaka o_prod.frm
-rw-r----- 1 systemd-coredump systemd-coredump 98304 9월 15 14:05 kaka o_prod.ibd
1) httpd -- volume --> /var/www/html
2) nginx -- volume --> /etc/nginx or /usr/share/nginx/html or /var/log/nginx/access.log | error.log 에 로그가 기록된다.
/
가 sdb의 공간을 모두 사용할 수 있음webapp
이 sda의 공간을 모두 사용할 수 있음docker: Error response from daemon: --storage-opt is supported only for overlay over xfs with 'pquota' mount option.
See 'docker run --help'.
조건 1. overlay over xfs
조건 2. with 'pquota'
kevin@hostos1:~$ docker info
Storage Driver: overlay2
Backing Filesystem: xfs
cat /etc/fstab
application과 database가 결합된 Container 결합 환경 구성
-container화(Con