Docker Cannot find module '/src/server'

Hi guys!

When I try to run the docker image as shown in hugomods docs with:

docker run -p 1313:1313 \
  -v ${PWD}:/src \
  hugomods/hugo \
  hugo server --bind

I get this error log:

  throw err;
Error: Cannot find module '/src/server'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  requireStack: []
Node.js v21.4.0

If I do:

docker run \

  -v ${PWD}:/src \

  hugomods/hugo \

  npm i

I get:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /src/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/src/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-02T12_39_55_260Z-debug-0.log

(but that .npm directory doesn’t even exist)

Can anyone provide a working docker compose??

Could you please double check if the command is correct?

As the image shown, the command should be hugo server instead of server, Previously, some users whose switch from klakegg/docker-hugo image also encountered related issues, but hugomods/hugo doesn’t mapping hugo commands, e.g. server to hugo server.

1 Like

Okay… that was some proper lack of attention on my side! sorry!!

Now I get, though:

Error: command error: Unable to locate config file or config directory. Perhaps you need to create a new site.
Run `hugo help new` for details.

But the conteiner just stops, so it doesn’t seem that I am doing all that’s needed yet. Is that the default docker experience expected?

No problem.

The error indicates that you may not running the command on your site root, or forgot to mount the site root on /src.

To fix this, you will need to:

  1. Enter the site folder.
$ cd /path/to/my-site
  1. And then mount current working directory on /src.
docker run -p 1313:1313 \
  -v ${PWD}:/src \
  hugomods/hugo \
  hugo server --bind
  • -v ${PWD}:/src mounts the current working directory (site root) on /src.

Solved it, thanks.

If translated this to a docker file like this:

version: '3'

    image: hugomods/hugo:latest
      - 1313:1313
      - /home/username/dockers/my-web-name:/src
    command: hugo server --buildDrafts --buildFuture --bind

And, I created a basic hugo.yaml on that my-web-name folder.

Do you think the compose is fine?

The docker seems to keep running fine now.

But 3 other new dockers appear (not shown with docker ps but I can see them exited in portainer):

  • bold_mccarthy
  • eloquent_kapitsa
  • pedantic_jennings

I can see different errors on the logs for them (one has the NPM errors from previous posts… other the error about the config file…). No one of them is running.

Is that expected?

Also, how do you enter that docker terminal?

docker exec -u 33 -it hugo-hugo-1 /bin/bash                                                                                                                                                                                                                         
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown

Do you think the compose is fine?

Yes, I tested your docker-compose.yaml with my own repo, it works great.

one has the NPM errors from previous posts.

The step about npm i is optional, which is used to install dependencies via NPM, just ignore it if your site/theme doesn’t depends on it.

other the error about the config file.

As I commented above, there isn’t a hugo site inside of container’s /src folder.

Also, how do you enter that docker terminal?

You may need to replace /bin/bash with /bin/sh, or use built-in commands, e.g. ls.

➜  ~ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS                    PORTS                    NAMES
dbd25dab5977   hugomods/hugo:latest     "docker-entrypoint.s…"   6 minutes ago   Up 4 minutes    >1313/tcp   theme2-hugo-1
ea9667748a7d   postgres                 "docker-entrypoint.s…"   6 weeks ago     Up 52 minutes             5432/tcp                 gotrue-db-1
9a92efbffec8   louislam/uptime-kuma:1   "/usr/bin/dumb-init …"   7 weeks ago     Up 52 minutes (healthy)>3001/tcp   uptime-kuma
➜  ~ docker exec dbd25dab5977 which bash
➜  ~ docker exec dbd25dab5977 which sh
➜  ~ docker exec dbd25dab5977 ls /src

I am getting same error in react native, as i run this command “npx run android”

Hmm, that docker image does not include android module/CLI, I think you’ve to install it by some way, I don’t know react native, could not provide further help on it.