3

im trying to install the Hugo tool in docker file following this guideline

https://gohugo.io/getting-started/installing/#debian-and-ubuntu

What I did is the following

FROM debian:11.3
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
         hugo
RUN ["hugo version"]

The docker build working except the last statement RUN ["hugo version"]

the error is > [3/3] RUN ["hugo version"]: #7 0.173 container_linux.go:380: starting container process caused: exec: "hugo version": executable file not found in $PATH how can I add it to the path, I assume that if I download it it should be there but no. any idea?

UPDATE

when I change it to RUN hugo version

I got the following output without the version printed, any idea what am I missing here?

#7 [3/3] RUN hugo version
#7 sha256:d032565cca2aac041e6791690dbcb32f2dc9d024d05699f67d21eb51cb39b0fc
#7 CACHED

#8 exporting to image
#8 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#8 exporting layers done
#8 writing image sha256:db76bafd84f0bdf930625714a72e2d0e1967578c48df0ffd0b4fc869c802f18f done
#8 DONE 0.0s
Nam G VU
  • 33,193
  • 69
  • 233
  • 372
PJEM
  • 557
  • 7
  • 33
  • 1
    The JSON-array form forces `"hugo version"` to be a single word, and it's looking for a command with a space in the filename in `/usr/bin`. Remove the quotes; `RUN hugo version`. – David Maze Jun 01 '22 at 16:42
  • @DavidMaze- thanks, I tried, `RUN hugo version` it but it doesn't display the version, any idea? anything else to do? – PJEM Jun 02 '22 at 07:10
  • What does it print? Does `docker build --progress=plain .` help ([When using BuildKit with Docker, how do I see the output of RUN commands?](https://stackoverflow.com/questions/55756372/when-using-buildkit-with-docker-how-do-i-see-the-output-of-run-commands))? – David Maze Jun 02 '22 at 09:26
  • @DavidMaze - `#7 [3/3] RUN hugo version #7 sha256:d032565cca2aac041e6791690dbcb32f2dc9d024d05699f67d21eb51cb39b0fc #7 CACHED #8 exporting to image #8 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00 #8 exporting layers done #8 writing image sha256:db76bafd84f0bdf930625714a72e2d0e1967578c48df0ffd0b4fc869c802f18f done #8 DONE 0.0s ` – PJEM Jun 02 '22 at 10:25
  • @DavidMaze - i've update the question with the output – PJEM Jun 02 '22 at 10:28

2 Answers2

4

When docker build executes the line: RUN hugo version, then by default, it does not show the output of the run commands that were not loaded from the cache. And hence you are not seeing its output.

When I ran docker build command with this flag: --progress=plain, I could see the output of "non-cached" line for RUN command. More details can be found in this answer. Here is the screenshot for the output I got: enter image description here

A few observations:

  1. I saw in one of the comments that you tried to run docker build using this flag but it still did not work. This is because, if you closely observe, that "RUN hugo version" line is "CACHED". And this flag --progress=plain shows intermediate steps of the lines that are not cached or freshly executed. So, if you wish to view the output, you need to first clear your docker build cache and all the dangling images using the commands:
$docker builder prune -a
$docker image prune -a

After this step, you will be able to freshly execute all your build steps and will be able to see output of RUN hugo version.

  1. To keep your hugo container running after you spin it from the image you build, you need to specify either CMD or ENTRYPOINT command. The command specified with these dockerfile instructions are executed only when you spin a container from the image that you have already built, not when the image is being built. For example if my dockerfile is:
FROM debian:11.3
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
         hugo
CMD hugo version

The output during build would be: enter image description here The instruction CMD hugo version is not executed.

After I run a container from this built image via command: enter image description here Then only I would see the output of this instruction coming.

I hope this helps in building the understanding!

  • Thanks a lot 1+ , is there any other smaller image which I can use to build it ? – PJEM Jun 06 '22 at 10:21
  • In case, its not a strict requirement to only use debian image, then you can try to use alpine linux image which is very light weight (~ 5MB). Link: https://hub.docker.com/_/e7e5dbc4-2103-4b7c-9409-b0ca32ce3d83 – lifeLongLearner Jun 06 '22 at 10:37
  • Yes of course, but for alpine it doesnt work with the apt-get etc – PJEM Jun 06 '22 at 11:50
  • HI, any idea how we can do it on alpine? – PJEM Jun 07 '22 at 09:58
  • I found this dockerfile that is leveraging alpine base image and installing hugo using tarball. you can have a look at it: https://github.com/jonathanbp/docker-alpine-hugo/blob/master/Dockerfile – lifeLongLearner Jun 07 '22 at 16:51
0

You can run the docker build command with --no-cache to see the output without cache:

Full Dockerfile:

FROM debian:11.3
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
         hugo
RUN hugo version

Full command:

docker build . --progress plain --no-cache

This displays:

#6 [3/3] RUN hugo version
#6 sha256:d032565cca2aac041e6791690dbcb32f2dc9d024d05699f67d21eb51cb39b0fc
#6 0.494 Hugo Static Site Generator v0.80.0/extended linux/amd64 BuildDate: 2021-07-18T09:31:51Z (debian 0.80.0-6+b5)
#6 DONE 0.5s

Also, you need to keep the command and parameters separate when using the []-syntax, so it would look like RUN ["hugo", "version"]

Swerik
  • 41
  • 1
  • 7