-
Docker Image
Liệt kê các images có sẵn trong docker
Tải images từ DockerHub
Xóa image
Tìm images từ DockerHub
Run image -
Docker Container
Tương tác ngoài container
Tương tác trong container
Xóa container
Commit container -
Container commit
Xuất image thành file
Load image file vào docker
Set image name và image tag -
Docker Volume
Chia sẻ thư mục giữa host và container
Chia sẻ thư muc giữa các containers
Tạo volume mới
Mapping thư mục trên Host vào volume khi tạo
Duyệt các volumes
Xem thông tin volume
Xóa volumes
Run và mount volume vào container
docker images
docker pull <image_name>:<tag_name>
- tag_name: default
lastest
docker image rm [IMAGE]
docker search <image_name>
docker run {option} [IMAGE] {command}
Short | Option | Meaning |
---|---|---|
t |
--tty |
mở một thiết bị đầu cuối (terminal) |
i |
--interactive |
cho phép tương tác với container |
d |
--detach |
chạy ngầm container |
h |
--hostname <string> |
đặt hostname cho container |
|
--name <string> |
set name cho container |
-v |
--volume <pathDirHost>:<pathDirContainer> |
Mount thư mục từ host vào container |
|
--rm |
tự động xóa container sau khi exist |
docker ps {options}
Option | Meaning |
---|---|
a |
tìm tất các container running & stopped |
- Chạy container:
docker start [CONTAINER]
, use option-i
to--interactive
this container! - Đăng nhập lại running container:
docker attach [CONTAINER]
- Dừng container:
docker stop [CONTAINER]
- Chạy 1 lệnh:
docker exec [CONTAINER] <string_command>
, ex:docker exec ubuntu01 ls
- Mở thêm 1 terminal mới (new session):
docker exec -it [CONTAINER] bash
- Thoát container, stop container:
exit
- Thoát nhưng vẫn giữ container chạy:
Ctrl+P Ctrl+Q
docker rm {options} [CONTAINER]
Short | Option | Meaning |
---|---|---|
f |
--force |
Xóa kể cả khi container đang chạy |
- Note: Nếu muốn commit một container thì container đó phải ở trạng thái
stopped
docker commit [CONTAINER] <image_name>:<tag_string>
docker save -o <filename>.tar [IMAGE]
docker load -i <filepath>.tar
- Note: Sau khi load image vào docker thì ta cần set name và tag cho image đó, chi tiết thực hiện mô tả trong bước tiếp theo
docker tag [IMAGE_ID] <image-name>:<image_id>
- Note: Có thể dùng cách này để đổi name và tag của image hiện có sang name và tag mới
docker run {options} -v <pathDirHost>:<pathDirContainer> [IMAGE]
- Thực hiện chia sẻ thư mục giữa các
CONTAINER1
vàCONTAINER2
docker run -it {option} --name 'CONTAINER2' --volumes-from [CONTAINER1] [IMAGE]
docker volume create <volume_name>
docker volume create --opt device=<path_host> --opt type=none --opt o=bind <volume_name>
docker volume ls
docker volume inspect <volume_name>
docker volume rm <volume_name>
docker run {option} --mount source=<volume_name>,target=<dir_path_on_container> [IMAGE]
- Note: loại ổ đĩa này không thể sử dụng option
--mount
khi gắn vào container khi chạy mà phải sử dụng option-v