AIoT.IO.VN
AIoT.IO.VN
🌐 SONG NGỮ

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

Ng Nghia Phan • • ⚡ 2 phút đọc • -- lượt xem • --
VI EN
MỤC LỤC BÀI VIẾT (Nhấn để xem)

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 prerequisites
sudo apt install apt-transport-https ca-certificates git curl software-properties-common gnupg-agent -y
# add docker gpg key
curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
# add docker software repository
sudo 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 docker
sudo apt install docker-ce docker-compose containerd.io -y
# enable and start docker service
sudo systemctl enable docker && sudo systemctl start docker
# add the current user to the docker group
sudo usermod -aG docker $USER
# reauthenticate for the new group membership to take effect
su - $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 directory
mkdir ~/docker/mkdocs
# set owner of working directories
sudo chown "$USER":"$USER" ~/docker -R
# allow the container to write to working directories
sudo chmod a+rwx -R ~/docker/mkdocs
# run mkdocs container
docker 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 container
docker stop mkdocs
# edit the mkdocs configuration file
sudo 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 container
docker start mkdocs
  1. Quay lại trình duyệt và refresh trang.1

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

  • Tutorial gốc: i12bretro 0986
  • Video gốc: Run MkDocs - Read the Docs Alternative - in Docker

Nguồn


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

Bình luận & Thảo luận 0

Chia sẻ thắc mắc, phản hồi hoặc kinh nghiệm thực chiến của bạn