Docker Community Forums

Share and learn in the Docker community.

Container command '/bin/sh' not found or does not exist

Dear all,

I’m facing following while trying to start a container from an image I buid myself:

Container command '/bin/sh' not found or does not exist..

Basically I run following command

docker run -d -P --volumes-from=ol7-pgdata --name pgdb1 -h pgdb1 -e DBNAME=PGDB1 -e OPNAME=deploy postgres/pgaas

This container should start a script /tmp/run_pgaas.bash to create a brand new Postgres database. here the Dockerfile I used to build the image:

FROM oraclelinux/postgres:9.5.3
MAINTAINER david.hueber@dbi-services.com

EXPOSE 5432

USER postgres

RUN wget http://172.17.0.1/Scripts/run_pgaas.bash -O /tmp/run_pgaas.bash

RUN chmod +x /tmp/run_pgaas.bash

CMD /tmp/run_pgaas.bash -d ${DBNAME} -o ${OPNAME}

What I not understand is that if I try to do the smae manually it works fine. I tried:

  1. starting a container based on oraclelinux/postgres:9.5.3 --> docker run it oraclelinux/postgres:9.5.3 /bin/bash
  2. su as postgres user
  3. Check that /bin/sh is available
  4. wget the script in /tmp
  5. run the script

All this works. the issue comes once I try to “package” that in an image.

Do you have any clue?

Many thanks

What is the image oraclelinux/postgres? No such Docker image is available on Docker Hub.
For Postgres, use the official image
https://hub.docker.com/_/postgres/

Hi dvohra,

thanks for your feedback. Didn’t knew that it was mandatory using a pre-build image from the hub. The idea is to build our own image with our best practices for the compilation and setup.

The oraclelinux/postgres image is a basic Oracle Linux 7.2 with Postgres Community installed in it. This image works fine as I can start a container based on it running bash and then manually create and operate Postgres databases in it.

When I try to “automate” that I getting the error above which is not Postgres related indeed. The issue seems to be having a script in the CMD parameter which starts with #!/bin/bash

What I do not understand is that bash is available in the image, so I get the not found error on it??

Looking to the CMD statement, I found that giving it in that form: CMD /tmp/run_pgaas.bash .........and not as a JSON array, makes it started with /bin/sh -c. I guess this is part which fails, but I can’t find why as /bin/sh is available in the image.

Cheers

While custom image for postgres could be used the official image should be preferred.

I got your point, but the issue is not postgres related.

It looks like I’m missing something the image building process and the CMD function.

I made a much easier test by writting a dummy script test.bash which just make a simple ls -lart $HOME

If a build an image as following:

RUN wget http://172.17.0.1/Scripts/test.bash -O /tmp/test.bash
RUN chmod +x /tmp/test.bash
CMD /tmp/test.bash

Then it works and the script is started as root.
If now I make it that way:

RUN wget http://172.17.0.1/Scripts/test.bash -O /tmp/test.bash
RUN chmod +x /tmp/test.bash
RUN chown test:test /tmp/test.bash

USER test
CMD /tmp/test.bash

Then I get again the error test.bash: command not found

Basically I’m able to run a command as root, but not as any other user

For the /bin/hash command to be available the image should be built from a Linux based image as specified in the FROM instruction. Is the oraclelinux/postgres image based on a Linux image?

Yes correct, I didn’t past the FROM and MAINTAINER part, but the image is based on an Oradle Linux 7.2 image.

Build operation works.

Use an ENTRYPOINT instead of CMD.

Thanks for the hint.

I tested deeper and find out that it works also with CMD, but the issue comes from the volumes.

Basically if I run: docker run -dt --name=test1 -h test1 -e DBNAME=DB1 -e OPNAME=deploy -P
then it works fine.

If now I had volumes in it: docker run -dt --name=test1 -h test1 -e DBNAME=DB1 -e OPNAME=deploy -P --volumes-from=dbdata
then I get again the error: Container command ‘/bin/sh’ not found or does not exist…

Do you see reason why the the volumes would impact the command execution?

@dhueber Did you end up figuring out the issue?