2

How can I run multiple commands inside a buildah container using bash's boolean AND && operator from the host's command line?

Here's an example of my issue that starts from a debian image:

$ buildah pull debian:buster && container=$(buildah from debian:buster)
$ buildah run $container -- apt -y update && apt -y upgrade
Hit:1 http://security.debian.org/debian-security buster/updates InRelease
Hit:2 http://deb.debian.org/debian buster InRelease
Hit:3 http://deb.debian.org/debian buster-updates InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
bash: apt: command not found...
Install package 'apt' to provide command 'apt'? [N/y]

My host shell interprets the boolean AND && outside the command for buildah. My expectation is to have the right side of the boolean AND to be run inside the buildah container.

EarthIsHome
  • 225
  • 2
  • 8
  • untested: Try quoting the command you want to execute: `buildah run $container -- 'apt -y update && apt -y upgrade'`. *Some* programs interpret a command string as a singe shell command, but not all programs do that, it depends on how `buildah` was developed. – user000001 Dec 26 '20 at 14:03
  • @user000001 I'm not very familiar with Go, but it seems like `buildah run` only allows a single command and its arguments: https://github.com/containers/buildah/blob/ffef8a6c0b258c892299aef86405ec4d2377d0c5/cmd/buildah/run.go#L84 – EarthIsHome Dec 26 '20 at 21:13

1 Answers1

5

How about?

buildah run $container -- sh -c 'apt -y update && apt -y upgrade'.

rhatdan
  • 271
  • 1
  • 3
  • 1
    This works, but why do we need to do that? Could you wrap the part after `--` with quotes and have the `buildah run` command accept the whole string? – FilBot3 May 16 '22 at 15:20