Docsy`s Interesting Tricks

001. if date is in the future, this markdown file will not be shown right now

---
title: "Docker使用"
date: 2024-07-19
categories:
  - blog
  - DevOps
  - Docker
---

and today is 2024-07-18, so that no blog will be shown within this section.

002. hugo server change detection does not work? How to fix it.

Date: Aug07.2024

LNK: hugo server intro page

By default hugo will also watch your files for any changes you make and automatically rebuild the site. It will then live reload any open browser pages and push the latest content to them. As most Hugo sites are built in a fraction of a second, you will be able to save and see your changes nearly instantly.

Problem

but when i edited my files via volume of docker which shared from host to guest os and the host os is windows 10 and the guest os is ubuntu 22.04, nothing will happen anyway.

``the solution which comes from ChatGPT-4o`

The issue you are encountering with Hugo not detecting file changes in a Docker volume shared directory could be related to how Docker and WSL handle file system notifications. Here are some steps you can try to troubleshoot and resolve the issue:

  1. Check File System Notifications: Ensure that file system notifications are correctly set up in your Docker container. Sometimes, the way Docker handles file changes in volumes can cause issues with live reload.

  2. Use Polling for File Changes: You can configure Hugo to use polling instead of relying on file system notifications. This can be done by setting the --poll flag when running the Hugo server. For example:

    hugo server --poll 300ms
    

    This will make Hugo poll for changes every 300 milliseconds.

  3. Verify Volume Mount Options: Ensure that your Docker volume mount options are set correctly. You can specify the :cached option to improve performance:

    docker run -v /path/to/your/hugo/project:/src:cached -p 1313:1313 klakegg/hugo server
    
  4. Check Docker and WSL Versions: Make sure you are using the latest versions of Docker Desktop and WSL. Updates often include bug fixes and performance improvements.

  5. Restart Docker and WSL: Sometimes, simply restarting Docker and WSL can resolve issues with file change detection.

  6. Check Docker Logs: Look at the Docker container logs to see if there are any errors or warnings related to file system notifications or Hugo server.

  7. Test Outside Docker: As a troubleshooting step, try running Hugo directly on your Windows machine or in a native Ubuntu installation (not within Docker) to see if the issue persists.

Here is an example Docker command with the polling option:

docker run --rm -it -v /path/to/your/hugo/project:/src -p 1313:1313 klakegg/hugo server --poll 300ms

By trying these steps, you should be able to determine whether the issue is with Docker’s handling of file changes or something else in your setup. If you need further assistance, feel free to ask!

final

... 
hugo server --bind 0.0.0.0 --port 1313 --disableFastRender --poll 1000ms
...

this fixed my problem!

003. How to disable/enable the message of current blog`s last modify date ?

vim hugo.yaml
enableGitInfo: false
showLastUpdated: false

choose false will turn every message off and true will on