1

I've created a docker image, and attempted to run it like this:

IMAGE=$(docker build --network=host -q .)

docker run \
        --network=host \
        --rm $IMAGE sh -c "cd bamboo && ./publish.sh"

The output is:

sh: ./publish.sh: not found

This variation of the command

IMAGE=$(docker build --network=host -q .)

docker run \
        --network=host \
        --rm $IMAGE sh -c "cd bamboo && ls -l"

shows:

-rwxr-xr-x    1 node     node           646 Nov 25 01:40 publish.sh

Outside the container (whose content is copied into the container via the docker file), while in same parent folder as the above script, running

cd bamboo & ./publish.sh

works as expected. Any ideas what I can be doing wrong?

I found this similar question: Container command '/start.sh' not found or does not exist, entrypoint to container is shell script

and it mentioned line ending on Windows (where I am running Docker) can be problematic. I confirmed my line ending are LF rather than CRLF.

EDIT: The first few lines of the called script is this:

#!/bin/bash

set -ex

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

and my dockerfile looks like this:

FROM node:12.16.2-alpine3.11

WORKDIR /app

# node image creates node user for security purposes
RUN chown -R node:node /app

USER node

COPY --chown=node:node . .

RUN yarn install --no-progress --pure-lockfile

RUN yarn build
Notre
  • 1,093
  • 3
  • 13
  • 26
  • 2
    What's the first line of the script? (Or, if it's really only 646 bytes, what's the entire script?) What's in the Dockerfile? In particular this can happen if you declare a script to require a non-standard shell (like `#!/bin/bash`) but use a base image that doesn't have it (like Alpine). – David Maze Nov 25 '20 at 05:32
  • Thanks David, I updated the question. And you're 100% right - my base image is alpine. Sorry for my ignorance, but is bash a non-stand shell? What could I use with alpine? – Notre Nov 26 '20 at 18:14
  • 2
    The Alpine base image in particular contains a very light-weight shell implementation that confirms to the POSIX standard, but no more; the `$BASH_SOURCE` environment variable and array-variable syntax aren't part of the standard. You can use `#!/bin/sh` instead, if you limit yourself to the standard shell features. – David Maze Nov 26 '20 at 21:41
  • Excellent, thank you David – Notre Nov 27 '20 at 01:35

0 Answers0