简体   繁体   中英

How do you compile Arduino programs using docker?

I want to compile arduino programs using docker.

This is my Dockerfile:

FROM zoobab/arduino-cli

Then I build the docker image and run it like this:

$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/).

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 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.

What should my Dockerfile and docker run command be? For the Dockerfile I tried:

FROM zoobab/arduino-cli

FROM ubuntu:xenial

ADD mycommands.bash ./

mycommands.bash contains the commands listed above.

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.

You cannot combine two images like that. The last image you use (last FROM) is the image where your script runs.

You implemented your Dockerfile (accidentially) as 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"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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