-4

I try to make container on Ubuntu, which should output "Hello" on terminal. I have main.zsh:

#!/usr/bin/zsh

echo "Hello"

And I have Containerfile:

FROM ubuntu:latest
WORKDIR /app
COPY main.zsh /app/hello.zsh
RUN chmod +x ./hello.zsh
CMD ./hello.zsh

When I run this container I have this error:

podman run localhost/hello:latest
/bin/sh: 1: ./hello.zsh: not found

How can I resolve it?

4
  • Check that you have zsh installed at /usr/bin/zsh Commented Apr 20 at 9:00
  • Alternatively you can use a shebang of #!/usr/bin/env zsh or #!/usr/bin/env bash instead. Commented Apr 20 at 9:01
  • Thank you very much. The container started correctly when I changed the shebang line to "/usr/bin/sh" and changed the script frame extension to *sh. Commented Apr 20 at 9:05
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Apr 20 at 15:38

1 Answer 1

0

zsh isn't necessarily installed in a Docker image. If you're using an Alpine-based image, it won't even have bash. In most cases, you need to change the "shebang" line to #!/bin/sh, and it will work on any Linux Docker image (provided it includes a shell; scratch and "distroless" images don't even have that).

#!/bin/sh
# ^^^^^^^ canonical path of the Bourne shell

echo "Hello"

This means that you need to limit yourself to the features of the POSIX shell (though this is generally good practice). That syntax doesn't include array-typed variables or some substitution syntaxes, and it doesn't support alternate command spellings like source (use . instead). The basic script you have here will work just fine.

You should make the script executable on the host system and check it into source control that way. Both typical source-control systems (e.g., Git) and docker build will preserve this permission setting; you don't normally need to RUN chmod.

I'd then tweak the Dockerfile to

FROM ubuntu:latest
WORKDIR /app
COPY main.sh ./     # target the current WORKDIR; don't repeat the absolute path
CMD ["./hello.sh"]  # JSON-array syntax is very slightly more efficient

With the correct executable bit and shebang line, you do not need to state the interpreter; do not say sh hello.sh.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.