1

What the docker image should run:

-bash-4.2$ pwd
/u/workspaces/compose/src

-bash-4.2$ ls
compileAndTest 

-bash-4.2$ vim compileAndTest
#!/usr/bin/env bash

echo 'hi'

Dockerfile

-bash-4.2$ pwd
/u/mybuild

-bash-4.2$ ls
Dockerfile

-bash-4.2$ vim Dockerfile
FROM java
WORKDIR /u/workspaces/compose
CMD /src/compileAndTest

build and run

-bash-4.2$ docker build -t myjavabuild .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM java
 ---> 69a777edb6dc
Step 2 : WORKDIR /u/eugenep/workspaces/compose
 ---> Using cache
 ---> 583d8616f495
Step 3 : CMD /src/compileAndTest
 ---> Using cache
 ---> d0458943d19e
Successfully built d0458943d19e
-bash-4.2$ docker run myjavabuild
/bin/sh: 1: /src/compileAndTest: not found

even though the path to the executable compileAndTest is specified in Dockerfile, it says not found

anyone know why?

2 Answers 2

1

The problem here is that you are not copying the /src/compileAndTest file to the filesystem of the container. You could use the ADD tag in the Dockerfile to achieve that.

FROM java
WORKDIR /u/workspaces/compose
ADD /u/workspaces/compose/src/compileAndTest /src/compileAndTest
RUN chmod +x /src/compileAndTest
CMD /src/compileAndTest
Sign up to request clarification or add additional context in comments.

6 Comments

when you are adding at the level, it comes with everything underneath?
it says " lstat u/workspaces/compose/src/compileAndTest: no such file or directory" when it exists while building the image
The file has to be in the same directory of the Dockerfile file.
then whats the point of supplying workdir and add? isnt that to get files from different dir?
The files are not copied into the filesystem of the container until you specify that in your Dockerfile using the ADD command. And about the WORKDIR, as the documentation says: The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
|
1

Add compileAndTest file from host machine is missing.

2 Comments

what do you mean? its the same host
If you want to copy any files from host machine to docker image, first you should add that files to docker image using add command. You dint added before so it says file not found. execute the below command, your file will not be listed, bcoz it was not copied from ur host to docker image. docker exec container_id ls src/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.