Skip to content
An`s Weblog
Go back

Using the Volume Instruction

Mục tiêu bài học

Học cách sử dụng lệnh VOLUME trong Dockerfile để:

Cấu trúc Dockerfile cơ bản

FROM nginx:latest

VOLUME ["/usr/share/nginx/html"]

Lưu ý:

Thao tác thực hành

1. Tạo cấu trúc thư mục & Dockerfile

cd docker_images/
mkdir volumes
cd volumes
vi Dockerfile

2. Build image

docker image build -t linuxacademy/nginx:v1 .

3. Tạo container từ image vừa build

docker container run -d --name nginx-volume linuxacademy/nginx:v1

Kiểm tra volume được tạo

1. Tìm volume gắn vào container

docker container inspect nginx-volume

Xem phần "Mounts" ➜ sẽ thấy volume được tạo tự động và mount vào /usr/share/nginx/html.

2. Lấy tên volume và inspect chi tiết

docker volume inspect <volume-name>

3. Kiểm tra dữ liệu có trong volume

sudo ls -la /var/lib/docker/volumes/<volume-name>/_data

Sẽ thấy các file HTML mặc định của NGINX.


Share this post:

Previous Post
Entrypoint vs Command
Next Post
Saving and Loading Images