Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose up with volumes "no such file or directory"

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?

like image 408
SNO Avatar asked Jan 24 '26 08:01

SNO


1 Answers

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

like image 178
Nitin Bhojwani Avatar answered Jan 25 '26 22:01

Nitin Bhojwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!