I'm creating a Dockerfile build script and would like to use bash commands. RUN uses /bin/sh by default. Is there some way to tell RUN to use /bin/bash instead?
No, this hardcoded to "/bin/sh -c"
One could of course link /bin/bash to /bin/sh in a previous build step.
I ended up changing my Dockerfile script to copy a file and use that rather than use the redirection I had been using in bash.
@dwatrous did you try RUN ["echo", "hello"]
will not be wrapped by /bin/sh
IIRC. So if you absolutely want bash, you can invoke it: RUN ["/bin/bash", "-c", "echo hello all in one string"]
.
Let us know if it solves your problem.
bash can be used manually by using it in RUN
instructions.
There's no intention or plan to make it possible to change it to bash.
I'll mark this as a doc issue because we might want to document this. It's the third or fourth time this question has popped up.
This can be closed now due to: https://github.com/docker/docker/pull/7489
so what's the story on this one?
@ORESoftware See the discussion above, and https://github.com/moby/moby/pull/22489, which added the SHELL
Dockerfile instruction (Docker 1.12 and up)
If you want to use a different shell for a single RUN
, use the Exec form (JSON) notation - as is being discussed above:
RUN ["/bin/bash", "-c", "echo I am now using bash!"]
If you want to change the default shell in your image (and during build), use the SHELL
Dockerfile instruction that was implemented in https://github.com/moby/moby/pull/22489:
SHELL ["/bin/bash", "-c"]
RUN echo I am now using bash!
Or, a combination of the above
FROM ubuntu
RUN echo I am using the default (/bin/sh)
RUN ["/bin/bash", "-c", "echo I am using bash"]
SHELL ["/bin/bash", "-c"]
RUN echo I am using bash, which is now the default
RUN ["/bin/sh", "-c", "echo I am using /bin/sh"]
RUN ["echo", "I don't use a shell at all"]
I know I am late to the party and yes this isn't the best solution, but it worked for what I needed
In my docker file after downloading and extracting the SDK I run these two commands
RUN cp /bin/bash /bin/sh
RUN echo "source ~/google-cloud-sdk/path.bash.inc" >> ~/.bashrc
RUN source ~/.bashrc
After that the gcloud command is available during the build and at run time
For those interested in strict OCI reproducibility, the Dockerfile call SHELL
doesn't seem to be in the OCIv1 specification, per podman 1.4:
STEP 2: SHELL ["/bin/bash", "-c"]
ERRO[0000] SHELL is not supported for OCI image format, [/bin/bash -c] will be ignored. Must usedocker
format
Update: Looks like thaJeztah is correct, some discussion regarding supporting this feature over at buildah: https://github.com/containers/buildah/issues/507
Update2: BUILDAH_FORMAT=docker
to the rescue
@qhaas don't think that has to do with OCI specifications, just the buildah implementation
Most helpful comment
@ORESoftware See the discussion above, and https://github.com/moby/moby/pull/22489, which added the
SHELL
Dockerfile instruction (Docker 1.12 and up)If you want to use a different shell for a single
RUN
, use the Exec form (JSON) notation - as is being discussed above:If you want to change the default shell in your image (and during build), use the
SHELL
Dockerfile instruction that was implemented in https://github.com/moby/moby/pull/22489:Or, a combination of the above