🌐 VI | EN

Chạy MkDocs bằng Docker và đổi sang theme Read the Docs

Nghia Phan
Nghia Phan
🌐 English version → Bài viết kỹ thuật Lượt xem
Quảng Cáo
Tài trợ

MkDocs là static site generator dùng Markdown và một file YAML để xây tài liệu dự án. Bài này chạy image polinux/mkdocs, lưu project ở ~/docker/mkdocs, sau đó dừng container để chỉnh mkdocs.yml sang theme readthedocs.1

Cài Docker trên Linux

Đăng nhập thiết bị Linux, rồi chạy:

# install prerequisitessudo apt install apt-transport-https ca-certificates git curl software-properties-common gnupg-agent -y# add docker gpg keycurl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -# add docker software repositorysudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"# install dockersudo apt install docker-ce docker-compose containerd.io -y# enable and start docker servicesudo systemctl enable docker && sudo systemctl start docker# add the current user to the docker groupsudo usermod -aG docker $USER# reauthenticate for the new group membership to take effectsu - $USER

Trên distro hiện đại, apt-key đã deprecated; kiểm tra Docker docs nếu repo hoặc package không còn phù hợp.1

Chạy MkDocs

  1. Tạo thư mục, đặt quyền và chạy container:
# create working directorymkdir ~/docker/mkdocs# set owner of working directoriessudo chown "$USER":"$USER" ~/docker -R# allow the container to write to working directoriessudo chmod a+rwx -R ~/docker/mkdocs# run mkdocs containerdocker run -d --name=mkdocs -p 8000:8000 -v ~/docker/mkdocs/:/mkdocs --restart=unless-stopped polinux/mkdocs
  1. Mở http://DNSorIP:8000.
  2. Kiểm tra MkDocs đã chạy.1

Đổi theme Read the Docs

  1. Quay lại terminal, dừng container và mở file cấu hình:
# stop the containerdocker stop mkdocs# edit the mkdocs configuration filesudo nano ~/docker/mkdocs/mkdocs.yml
  1. Thêm đúng dòng sau vào mkdocs.yml:
theme: readthedocs
  1. Nhấn CTRL+O, Enter, CTRL+X để lưu và thoát.
  2. Khởi động lại container:
# restart the containerdocker start mkdocs
  1. Quay lại trình duyệt và refresh trang.1
Quảng cáo

Backup và giới hạn

Backup ~/docker/mkdocs trước khi thay đổi theme hoặc image. Image nguồn dùng latest, vì vậy nếu cần reproducible build, mình sẽ pin version sau khi kiểm tra tag tương thích thay vì để cập nhật bất ngờ.1

Nguồn và video

Nguồn

Footnotes

  1. https://i12bretro.github.io/tutorials/0986.html — Run MkDocs - Read the Docs Alternative - in Docker (i12bretro) ↩ ↩2 ↩3 ↩4 ↩5

Quảng Cáo Được Tài Trợ
Hợp tác

Bình Luận & Thảo Luận

Góp ý, hỏi đáp và chia sẻ suy nghĩ của bạn

Markdown & QQ Emoji
Đang tải khung bình luận...