Skip to content
An`s Weblog
Go back

Inspecting Container Processes

1. Mục tiêu

2. Tạo container chạy nền

docker container run -it -d --name container_process centos /bin/bash

3. Xem các tiến trình container

docker container top container_process

Hiển thị danh sách tiến trình đang chạy. Khi mới khởi tạo chỉ có /bin/bash.

4. Truy cập container & chạy tiến trình

docker container exec -it container_process /bin/bash

Mở 1 shell mới trong container → chạy:

top

Ta sẽ thấy:

Thoát bash (exit) thì container vẫn chạy, vì bash PID=1 còn tồn tại.

5. So sánh exec vs attach

docker container exec -it container_process /bin/bash
docker container attach container_process

Nếu exit sau attach thì container sẽ bị stop.

Khởi động lại container:

docker container start container_process

6. Theo dõi tài nguyên container realtime

docker container stats

Giám sát CPU %, memory, network IO, block IO…

Để tạo tải:

docker container exec -it container_process /bin/bash
yum update

Khi đang update, stats sẽ tăng CPU & Memory.


7. Thoát khỏi stats


Tổng kết lệnh

LệnhMô tả
docker container topXem các tiến trình trong container
docker container exec -it <name> /bin/bashMở shell mới trong container
docker container attach <name>Gắn vào tiến trình chính của container
docker container statsGiám sát tài nguyên container realtime
docker container start <name>Khởi động lại container đã stop

Share this post:

Previous Post
Having Containers Start Automatically
Next Post
Managing Swarm Nodes