3

I'm a beginner in working with docker especially docker compose. Currently, creation my initial easy docker environment, I run into the first error and I've no clue why. I tried to search for a solution in stackoverflow but found nothing that could help me. Starting my docker with "docker-compose up" I get the following error:

$ docker-compose up
Removing errorinstance_app_1
Recreating 8a358dfcb306_8a358dfcb306_8a358dfcb306_errorinstance_app_1 ...
Recreating 8a358dfcb306_8a358dfcb306_8a358dfcb306_errorinstance_app_1 ... error
ERROR: for 8a358dfcb306_8a358dfcb306_8a358dfcb306_errorinstance_app_1 Cannot start service app: oci runtime error: container_linux.go:265: starting container process caused "exec: \"./run.sh\": stat ./run.sh: no such file or directory"
ERROR: for app Cannot start service app: oci runtime error: container_linux.go:265: starting container process caused "exec: \"./run.sh\": stat ./run.sh: no such file or directory"
ERROR: Encountered errors while bringing up the project.

So. Following my folder structure:

  • Project
    • docker-compose.yml
    • Docker
      • Java
        • Dockerfile
    • src
      • run.sh

Following my docker-compose.yml:

 version: '2'
    services:
      app:
        build:
            dockerfile: ./Docker/Java/Dockerfile
            context: .
        volumes:
            - ./src:/usr/local/etc/
        working_dir: /usr/local/etc/
        command: ./run.sh

And following my docker file:

FROM java:7-jdk-alpine
# WORKDIR /usr/local/etc

run.sh

echo "Hello world."

Yes, I know that I could do that solution only in a docker-compose file. But in the future I need to extend the Dockerfile.

Can someone help me respectively does anyone see the issue?

4
  • 1
    could you please change the command: /bin/bash and then check if the script exists in the /usr/local/etc/ directory as well as what permissions it has?
    – Sergiu
    Commented Oct 13, 2017 at 14:08
  • comment out the command, start a bash session. Once inside you should be on the working directory you're mentioning... also, check for the execution permissions as @Sergiu mentioned
    – sebagomez
    Commented Oct 13, 2017 at 15:38
  • Changing the command I get a "not found" exception. Having that command directly in Dockerfile "/bin/sh: bash: not found". Having that command in docker-compose file "ERROR: for java Cannot start service app: oci runtime error: container_linux.go:265: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory". Also tried only "bash"
    – SNO
    Commented Oct 16, 2017 at 10:08
  • Adding the CMD /bin/bash directly to dockerfile and running docker run -it <nam> /bin/bash. It works. But why it is not possible to run th bin/bash command from docker-compose file?
    – SNO
    Commented Oct 16, 2017 at 12:03

4 Answers 4

2

The problem is with the base docker image you are using in dockerfile:

FROM java:7-jdk-alpine

You are trying to start container by running run.sh bash script. But the above image doesn't support bash itself

For reference, you can see the documentation of above image in docker hub page here. Quoting the necessary portion here:

java:alpine

...

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar).

That's about the problem.

Now, I can think of 2 solutions:

  1. Just use java:7-jdk as base image instead of java:7-jdk-alpine
  2. Install bash on top of the base image java:7-jdk-alpine by changing dockerfile to:

    FROM java:7-jdk-alpine
    RUN apk update && apk upgrade && apk add bash
    #WORKDIR /usr/local/etc
    

    *source of steps to install bash in alpine linux is here

0

It looks like docker compose can't find your run.sh file. This file needs to be included in your docker image.

Change your Dockerfile to the following, then rebuild the image with docker build -t <YOUR_IMAGE_NAME> ..

FROM java:7-jdk-alpine
ADD run.sh /usr/local/etc/run.sh

Once your image is rebuilt, run docker-compose up again.

4
  • 1
    Thank you very much for your help. Having a question to that point. My understanding was, that the "volumes" setting in docker-compose should map the files into the image so that I don't need to add any files?
    – SNO
    Commented Oct 16, 2017 at 6:08
  • 1
    The docker-compose volumes maps files to the running container (i.e. at runtime when the container is running), not the image. In your docker-compose config, you are saying "Run the run.sh script when starting up the container", but run.sh doesn't exist, since it is not part of the image. The run.sh file needs to be added at build time.
    – grizzthedj
    Commented Oct 16, 2017 at 13:22
  • 1
    Ah ok. Good to know. So, assuming I have multiple files that are triggered by the run.sh. Do I need to "ADD" all those files? Do you have "best practises" for me how I can handle that on a clean way? For development my source folder including java files is to big (a few gb) to ADD all files everytime new respectively to build the docker image always new.
    – SNO
    Commented Oct 16, 2017 at 13:38
  • You can just add the entire directory so that you don't have to do multiple ADD statements in your Dockerfile. Since you already have a volume to map your local development folder src/ to /usr/local/etc/, you shouldn't have to rebuild your image after every code change. You would only need to rebuild when deploying to DEV, QA, or PROD environments.
    – grizzthedj
    Commented Oct 16, 2017 at 13:57
0

The easiest way to tackle the problem is to execute a bash session in the container, then inside the container, you have to check if the file exists in the indicated path if the file is not in the path, it must be included when you create the image into the docker file or through a volume inside de docker-compose.

Another thing to check is the relative path you are using. It will be clear when you check the existence of the file inside de docker container

docker exec -it CONTAINER_NAME bash

I recommend you to create a volume in the docker compose file, as it is the easier way, and also the best way.

there is a question that I want to do you, why are you putting the Dockerfile file inside a Java path?

It is not a good idea o guideline to follow The correct way is to put your dockerfile file into an environment folder, in such a way the dockerfile file is not related to the java source of your application

1
  • Thank you for the response. I have the following additional questions: How can I run docker exec -it CONTAINER_NAME bash? Currently my docker-compose is throwing the file not found error and so I have no running instance where I can run this command. What do you mean with having an environment folder? Could you give me an example? Thank you very much.
    – SNO
    Commented Oct 16, 2017 at 6:29
0

I got this Error quite a lot and after a lot of investigation, it looked like some images were corrupted.

Deleting those and rebuilding solve the problem. It was not docker installation or configuration itself.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.