SNO
SNO

Reputation: 866

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:

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?

Upvotes: 3

Views: 11373

Answers (4)

Nitin Bhojwani
Nitin Bhojwani

Reputation: 712

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

Upvotes: 2

zhrist
zhrist

Reputation: 1558

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.

Upvotes: 0

Mariano Di Maggio
Mariano Di Maggio

Reputation: 11

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

Upvotes: 0

grizzthedj
grizzthedj

Reputation: 7505

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.

Upvotes: 0

Related Questions