AbstractSetting up an embedded tool chain on a local PC or laptop requires very often to spend an enormous amount of time for installation and configuration of the individual software packages. It ends up in a "golden" installation on a single computer that is kept like a treasure. But with each new package installed on this computer, the golden installation is in danger.
Docker provides a light weight virtualization engine that runs on Linux, Windows or MacOS.
Docker containers contain virtual guest OSes and can easily be configured, deployed and executed. The article descibes how to create a suitable container for embedded software development and how to use it.
Installing DockerIn the first step, install docker on the local PC. We use the Docker Community Edition (Docker CE). On the docker installation
page click on your OS to get the latest installation instructions.
To run docker on Ubuntu as normal user, do
- add the user to the "docker" group
sudo gpasswd -a
- log off and log on again
$ docker run hello-world
Create the first Docker ImageCreate a working directory and add the file Dockerfile in it.
Edit the file Dockerfile and add the following content:
FROM ubuntu MAINTAINER Main Tainer firstname.lastname@example.org RUN apt-get update \ # install packages && apt-get -y install \ # build system related scons mercurial \ # Python packages python python-pip \ # AVR Tools binutils-avr gcc-avr avr-libc \ # Documentation tools doxygen # we skip doxygen-latex here, otherwise the image becomes "huuuuge" RUN useradd -ms /bin/bash uracoli USER uracoli RUN mkdir /home/uracoli/work WORKDIR /home/uracoli/work # command is running at start of the container CMD \ echo == starting uracoli-development environment == \ && /bin/bash
To create the image run the command:
$ docker build -t my-uracoli-env .
The command creates an image named "my-uracoli-env".
It inherits from the latest Ubuntu installation. The "RUN" commands
- install the standard Linux packages required to compile the µracoli project
- create a user uracoli
- create a working directory /home/uracoli/work
The "CMD" statement at the end of the file is executed at every start of the container. It issues a message and starts bash.
First Run of the Container
After successfully creating the container, run the command
docker run -t -i my-uracoli-env
in a terminal
$ docker run -t -i u5idev == starting uracoli-development environment == uracoli@6f065accfc17:~$
On this shell prompt type pwd to see that you are in the directory /home/uracoli/work.
Your first development session might start with the following commands:
uracoli@9311c77b2d54:~/work/uracoli$ hg clone http://hg.savannah.nongnu.org/hgweb/uracoli/ destination directory: uracoli ... uracoli@9311c77b2d54:~/work/uracoli$ cd uracoli uracoli@9311c77b2d54:~/work/uracoli$ scons radiofaro scons: Reading SConscript files ... build 1 of 104 boards ...
Adding some ComfortAfter ending (Ctrl-D) and restarting the docker session, you will notice that the docker container is suffered from amnesia. That means, after the next restart the directory /home/uracoli/work is empty. Also editing source code with terminal tools like "nano" or "vi" might not fit your regular development habits. To circumvent this, we simply map a local directory from the host computer into the docker container. So you can edit the files from the host machine with your favourite IDE or source-code editor. Mapping a local directory to docker is done by passing the -v option to the run command.
docker run -v /home/axel/Work/uracoli-aw:/home/uracoli/work -it my-uracoli-env
Now you can edit the files on the host compile and compile it in the docker container.
Mapping Serial Devices into DockerOn Ubuntu it is possible to map serial devices into the docker container with the following command:
$ docker run --device=/dev/ttyUSB0 -v .... -it my-uracoli-env
System Clean UpWhile experimenting with docker, a lot of logfiles from different sessions and temporary images may waste a enormous amount of disk space. To get rid of this left overs, you can use the follwing commands on Linux/Ubuntu to clean the system
$ docker rm $(docker ps -aq) $ docker rmi $(docker images -f "dangling=true" -q)