klakegg/docker-hugo

Using Docker for Dev

robertdown opened this issue · 13 comments

I have got the ext-alpine image successfully running using the following docker-compose:

version: '3'

services:
  app:
    image: klakegg/hugo:ext-alpine
    command: server
    ports:
      - 1313:1313
    volumes:
      - .:/src

this is successfully running the hugo server on the docker with the volume content. However, once running, if I edit anything in my repo (located on host and brought in with the volume) the changes don't trigger the hugo refresh. If I drop into the instance I can see the changes but for whatever reason Hugo doesn't recognize the changes. Any thoughts on how I could accomplish this?

Hi @robertdown

You can solve this adding --disableFastRender after server command. I usually use it in combination with parameters -D (--buildDrafts) and -F (--buildFuture)

It works for me.

Hi @robertdown

You can solve this adding --disableFastRender after server command. I usually use it in combination with parameters -D (--buildDrafts) and -F (--buildFuture)

It works for me.

Here is the updated docker-compose.yml file, including the disableFastRender, still no luck.

version: '3'

services:
  app:
    image: klakegg/hugo:ext-alpine
    command: server -DF --disableFastRender
    ports:
      - 1313:1313
    volumes:
      - .:/src

Running this via docker-compose up and here is the output

Recreating hugo-site_app_1 ... done
Attaching to hugo-site_app_1
app_1  | Start building sites … 
app_1  | hugo v0.95.0-9F2E76AF+extended linux/amd64 BuildDate=2022-03-17T10:45:02z VendorInfo=hugoguru
app_1  | INFO 2022/04/20 21:25:13 syncing static files to /
app_1  | 
app_1  |                    | EN
app_1  | -------------------+------
app_1  |   Pages            |  72
app_1  |   Paginator pages  |   0
app_1  |   Non-page files   |   2
app_1  |   Static files     | 480
app_1  |   Processed images |   0
app_1  |   Aliases          |  15
app_1  |   Sitemaps         |   1
app_1  |   Cleaned          |   0
app_1  |
app_1  | Built in 15398 ms
app_1  | Watching for changes in /src/{archetypes,content,layouts,package.json,static,themes}
app_1  | Watching for config changes in /src/config.yaml, /src/go.mod
app_1  | Environment: "DEV"
app_1  | Serving pages from memory
app_1  | Web Server is available at http://localhost:1313/ (bind address 0.0.0.0)
app_1  | Press Ctrl+C to stop

hello, running hugo server by default should trigger --watch set to true as per the docs, you can explicitly pass --watch to trigger updates automatically on file changes.

here is my implementation of docker-compose file i use for my hugo projects, hope this helps

Alas, I just ran into this issue myself last week. I took the liberty of creating an MCVE to aid troubleshooting, but please let me know if I may be of any further assistance.

I have the same issue on Windows 10 enterprise and Docker v20.10.17.
None of the above solutions worked.
I tried version 0.100.2-busybox as well.

No issue at all on osx.

I have the exact same issue with Angular. So it may not be an issue with this project.

It turns out it is an old classic issue for windows users.
In cases where Hugo CLI is running in a shared directory on linux VM on a windows host the dev server is not detecting file changes from the host environment. (ex: Whenever a docker dev environment is running on a windows host.).
This is because by default most watchers will use native file system change detection. And it is not working well in this shared situation.
For webpack (Angular) this is solved by adding a poll option.

So now let's find out a solution for Hugo.

Hugo 0.85.0 added a polling option, which is not strictly a solution, but may help workaround the issue.

https://gohugo.io/news/0.85.0-relnotes/

Example command line:
hugo server --poll 700ms

Thanks @DavidForster, it is working great.
I still wonder why it happens on some machines. A few years back while using windows I have never seen this issue.

Thanks, @LCluber and @DavidForster, for your helpful comments. Adding --poll did the trick for me as well. 👍

--poll working for me as well, commenting in case a solution is found as this is an interesting case

Confirming that Hugo version >= 0.85.0 with --poll <interval> is resolving the problem, though as previously stated is likely a workaround. Here is the docker-compose.yml file with the changes:

version: '3'

services:
  app:
    image: klakegg/hugo:ext-alpine
    command: server --poll 700ms --verbose
    ports:
      - 1313:1313
    volumes:
      - .:/src

I'm on MacOS/M1, and I don't have this problem when using Docker Desktop, but I do have this same problem when using either RancherDesktop or colima. None of the listed fixes (-DF, --watch --poll 700ms) seem to make a difference. Anybody have thoughts on the differences with the open source packages?