0

I'm trying to compile a C file named test.c using docker's gcc container.

I'm using the following command, I have put the test.c in my homein ubuntu.

sudo docker run -v /home/moomal/workspace/FypProject/WebContent/file/:/myapp.c:ro gcc:4.9 sh -c "gcc -o myapp /home/moomal/workspace/FypProject/WebContent/file/myapp.c; ./myapp"

It works cool, but, I want to change the folder from home to a folder inside my eclipse web project folder. I have an editor on a web page and then on compile it creates a test.c file inside a folder. I want to access that file.

I tried adding the path like /home/moomal/workspace/FypProject/WebContent/file but I get the error

   gcc: error: /home/moomal/workspace/FypProject/WebContent/file/myapp.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
sh: 1: ./myapp: not found
10
  • Did you try using an absolute path like the error suggests? e.g. /home/me/workspace/Web Content/... Commented Feb 20, 2015 at 13:02
  • @AdrianMouat yes, sir. Commented Feb 21, 2015 at 6:46
  • @AdrianMouat the it gives No such file or directory error Commented Feb 21, 2015 at 6:53
  • To be honest, it just sounds like you made a typo. Can you add to the question the exact command you execute and the result of running ls on the path? Commented Feb 21, 2015 at 11:47
  • I bet the space between Web and Content was not quoted. Commented Feb 22, 2015 at 3:00

1 Answer 1

1

You seem to be confused about several things here.

The -v HOST_PATH:CON_PATH argument can be used to mount files inside a container, as you seem to be attempting. The HOST_PATH can be a file or a directory. The CON_PATH determines where that file or directory will be in the container. In your case, I think you want:

-v /home/moomal/workspace/FypProject/WebContent/file/myapp.c:/myapp.c

Not just ...file/:/myapp.c. I'm not sure what you expected your version to do (how can a directory be mapped to a file?).

Also, in the shell command you give the path on the host, but as this is processed in the container, you need the path in the container i.e:

gcc -o myapp /myapp.c

Putting it together, I would expect to see something like:

sudo docker run -v /home/moomal/workspace/FypProject/WebContent/file/myapp.c:/myapp.c:ro gcc:4.9 sh -c "gcc -o myapp /myapp.c; ./myapp"
Sign up to request clarification or add additional context in comments.

6 Comments

Wow! that was it. What you said is absolutely correct. I had also tried this command: sudo docker run -v /home/moomal/workspace/FypProject/WebContent/file/:/myapp.c:ro gcc:4.9 sh -c "gcc -o myapp /myapp.c; ./myapp" So i guess I was kind of there. But thank you
No problem, glad I was able to help. It would help if you were a bit more precise in future though :)
I do have another question too though :P when using the Java container, I use the following command sudo docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac Main.java and if the Main.java doesn't have any errors it compiles and creates a Main.class file. If it has any errors it shows the errors in json format. Now, if the program has a System.out.print line, how do I show that as an output. I mean, if there are no errors it just compiles the program, i need the output of the program.
Okay. Update: I found out how to do it. just by running java filename. but how do I run the .class file created of the file that i run through my workspace? Because I can't find it at /home/moomal/workspace/FypProject/WebContent/file/ nor is it at home directory
You need to take some time to understand how volumes work. docs.docker.com/userguide/dockervolumes container-solutions.com/2014/12/understanding-volumes-docker If it still doesn't make sense after reading those, open a new question.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.