简体   繁体   English

如何使用 docker 编译 Arduino 程序?

[英]How do you compile Arduino programs using docker?

I want to compile arduino programs using docker.我想使用 docker 编译 arduino 程序。

This is my Dockerfile:这是我的 Dockerfile:

FROM zoobab/arduino-cli

Then I build the docker image and run it like this:然后我构建docker镜像并像这样运行它:

$docker build -t test .

$docker run -v C:/test/MyFirstSketch:/root/MyFirstSketch -it test

(Dockerfile is in /test/ and my Arduino Sketch - MyFirstSketch.ino - is in /MyFirstSketch/). (Dockerfile 在 /test/ 中,而我的 Arduino Sketch - MyFirstSketch.ino - 在 /MyFirstSketch/ 中)。

When the container is running, from the command prompt, I enter the following commands for arduino-cli and they work and my code in /MyFirstSketch gets compiled as expected.当容器运行时,在命令提示符下,我为 arduino-cli 输入以下命令,它们工作并且我在 /MyFirstSketch 中的代码按预期编译。

$arduino-cli core update-index

$arduino-cli core install arduino:avr

$arduino-cli compile --fqbn arduino:avr:uno MyFirstSketch

Now, to improve this, I want to put the above code in a bash file called mycommands.bash and be able to run it in docker.现在,为了改进这一点,我想将上面的代码放在一个名为 mycommands.bash 的 bash 文件中,并能够在 docker 中运行它。

What should my Dockerfile and docker run command be?我的 Dockerfile 和 docker run 命令应该是什么? For the Dockerfile I tried:对于我尝试过的 Dockerfile:

FROM zoobab/arduino-cli

FROM ubuntu:xenial

ADD mycommands.bash ./

mycommands.bash contains the commands listed above. mycommands.bash 包含上面列出的命令。

And here is the output:这是输出:

./mycommands.bash: line 2: arduino-cli: command not found

./mycommands.bash: line 3: arduino-cli: command not found

./mycommands.bash: line 4: arduino-cli: command not found

Thanks!谢谢!

Sorry to say that, but the problem is your Dockerfile.很抱歉这么说,但问题在于您的 Dockerfile。

You cannot combine two images like that.你不能像这样组合两个图像。 The last image you use (last FROM) is the image where your script runs.您使用的最后一个图像 (last FROM) 是运行脚本的图像。

You implemented your Dockerfile (accidentially) as MultiStage-Build: https://docs.docker.com/v17.09/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds您将 Dockerfile(偶然)实现为 MultiStage-Build: https ://docs.docker.com/v17.09/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds

This should work:这应该有效:

FROM zoobab/arduino-cli

COPY mycommands.bash .
CMD ["./mycommands.bash"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM