如何自定义docker gcc命令并添加自己的路径而不是/ usr / src [英] How to customize the docker gcc command and add own path instead of /usr/src

查看:656
本文介绍了如何自定义docker gcc命令并添加自己的路径而不是/ usr / src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker的gcc容器编译一个名为test.c的C文件。

我使用以下命令,我将test.c放在ubuntu中的 home 中。

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"

它很酷,但是我想将文件夹从 home 更改到我的eclipse Web项目文件夹中的一个文件夹。我在网页上有一个编辑器,然后编译它在文件夹中创建一个test.c文件。我想访问该文件。

我尝试添加路径,如 / home / moomal / workspace / FypProject / WebContent / file ,但是我收到错误

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


推荐答案

你似乎对这里的几件事情感到困惑。

You seem to be confused about several things here.

-v HOST_PATH:CON_PATH 参数可以用于将文件装载到容器中,就像您正在尝试的那样。 HOST_PATH 可以是文件或目录。 CON_PATH 确定文件或目录在容器中的位置。在你的情况下,我想你想要:

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

不只是 ...文件/:/ 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?).

另外,在shell命令中你给出了路径在主机上,但是由于这是在容器中处理的,所以您需要容器中的路径,即:

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"

这篇关于如何自定义docker gcc命令并添加自己的路径而不是/ usr / src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆