Live data from Hacker News

Dockerfmt: A Dockerfile Formatter

github.com

21–30 of 67 posts

Re: Dockerfmt: A Dockerfile Formatter

#21
post #20

waaaat? https://github.com/reteps/dockerfmt#:~:text=The%20RUN%20pars... I am firmly in the camp of RUN set -e ;\ export DEBIAN_FRONTEND=noninteractive ;\ etc etc so I guess this tool isn't for me

Is there any reason you prefer `set -e` over `&&`? I'm curious if this is a readability thing.

Re: Dockerfmt: A Dockerfile Formatter

#23

Earlier quoted context omitted.

Podman uses Dockerfiles too. Dockerfiles is the language for specifying a set of instructions for building container images.

It's not a very good one, but it is ubiquitous (it's also better if you remember to include the right syntax marker that enables heredocs): # syntax=docker/dockerfile:1 I suspect that the GP was really asking "why not use a different tool", like buildah https://buildah.io >, buildpacks https://buildpacks.io >, nix https://nix.dev/tutorials/nixos/building-and-running-docker-... >, kaniko https://github.com/GoogleConta…

When I've used buildah and kaniko, I still handed them a Dockerfile.

Re: Dockerfmt: A Dockerfile Formatter

#25
> The RUN parser currently doesn't support grouping or semicolons in commands

But then example show that it does support `&&`? Why the difference? I pretty much always write

  RUN foo && \
      bar && \
      :
but it seems syntactically identical to the also valid

  RUN set -e && \
      foo ; \
      bar ; \
      :

Re: Dockerfmt: A Dockerfile Formatter

#26

> The RUN parser currently doesn't support grouping or semicolons in commands But then example show that it does support `&&`? Why the difference? I pretty much always write RUN foo && \ bar && \ : but it seems syntactically identical to the also valid RUN set -e && \ foo ; \ bar ; \ :

[deleted]

Re: Dockerfmt: A Dockerfile Formatter

#27

Earlier quoted context omitted.

It's not a very good one, but it is ubiquitous (it's also better if you remember to include the right syntax marker that enables heredocs): # syntax=docker/dockerfile:1 I suspect that the GP was really asking "why not use a different tool", like buildah https://buildah.io >, buildpacks https://buildpacks.io >, nix https://nix.dev/tutorials/nixos/building-and-running-docker-... >, kaniko https://github.com/GoogleConta…

Buildah is the only serious alternative in my opinion. You lose automatic layer caching, but in exchange you can use the same tools (RUN, ADD, etc) within a much more powerful shell environment. I wrote a Buildah wrapper that uses a shell script harness to polyfill the familiar Dockerfile syntax while adding several extra goodies - mainly the ability to bake runtime arguments (mounts, ports...) into the image. Very h…

Buildah's ability to mount the container in an unshare environment is pretty magical for copying stuff in and out of it.

That said, in the end I'd still rather build containers with something other than an imperative sequence of commands, so my heart is going to be forever with nix2container and bazel's rules_oci.

Re: Dockerfmt: A Dockerfile Formatter

#28

> The RUN parser currently doesn't support grouping or semicolons in commands But then example show that it does support `&&`? Why the difference? I pretty much always write RUN foo && \ bar && \ : but it seems syntactically identical to the also valid RUN set -e && \ foo ; \ bar ; \ :

I prefer heredoc[1] syntax.

I find it more readable and portable.

[1] https://www.docker.com/blog/introduction-to-heredocs-in-dock...

Re: Dockerfmt: A Dockerfile Formatter

#29

> The RUN parser currently doesn't support grouping or semicolons in commands But then example show that it does support `&&`? Why the difference? I pretty much always write RUN foo && \ bar && \ : but it seems syntactically identical to the also valid RUN set -e && \ foo ; \ bar ; \ :

I prefer heredoc[1] syntax. I find it more readable and portable. [1] https://www.docker.com/blog/introduction-to-heredocs-in-dock...

Meta: In HN, prefix a line with 2 spaces to get code formatting, ex.

  # syntax=docker/dockerfile:1.3-labs
  FROM alpine
  RUN 
Non-meta: Do you happen to know how portable that is across old docker, podman/buildah, kaniko, etc.? I'd like to adopt it but I don't want it to bite me when I'm not running a recent version of literal docker.

Re: Dockerfmt: A Dockerfile Formatter

#30

> The RUN parser currently doesn't support grouping or semicolons in commands But then example show that it does support `&&`? Why the difference? I pretty much always write RUN foo && \ bar && \ : but it seems syntactically identical to the also valid RUN set -e && \ foo ; \ bar ; \ :

I use `mvdan/sh` [1] under the hood for processing the commands. So it will reformat

  if [ foo ] ; then
    bar
  fi
to

  if [ foo ]
  then
    bar
  fi
And also format your example to

  foo
  bar
In this type of situation, it becomes a little trickier to disambiguate when I need to add semicolons and a backslash, and when I need to add only backslashes. If you use `&&` -- you have disambiguated the two cases so I can format it.

[1] https://github.com/mvdan/sh

Post reply on HN