Running a Toaster Docker container
Docker is a software technology that provides operating system level virtualization. Functionality-wise it can be compared with a virtual machine, except that it suffers less of a performance penalty. On Linux it uses the resource isolation features of the Linux kernel to provide abstraction and process isolation. It allows you to create containers that run on Docker and are independent of the operating system underneath.
There are Docker instances of the Toaster user interface available, which will be introduced in this recipe.
How to do it...
- To install Docker on your Ubuntu 16.04 machine, add the GPG key for the official Docker repository to the system:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -- Then add the Docker repository to APT sources:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"- Next, update the package database with the Docker packages from the newly added repository:
$ sudo apt-get update$ sudo apt-get install docker-ce
- Add your user to the docker group:
$ sudo usermod -aG docker ${USER}$ su - ${USER}
- Finally, test run Docker by running the
hello-worldcontainer:
$ docker run hello-world- To run a
docker-toasterinstance, we will first create a directory in our host machine for thedockercontainer to store the builds:
$ mkdir /opt/yocto/docker-toaster- We can then instruct Docker to run the
crops/toastercontainer and point its/workdirdirectory to the local directory we just created:
$ docker run -it --rm -p 127.0.0.1:18000:8000 -v /opt/yocto/docker-toaster:/workdir crops/toasterNote
If you see the following error:Refusing to use a gid of 0Traceback (most recent call last): File "/usr/bin/usersetup.py", line 62, in <module> subprocess.check_call(cmd.split(), stdout=sys.stdout, stderr=sys.stderr) File "/usr/lib/python2.7/subprocess.py", line 541, in check_call raise CalledProcessError(retcode, cmd)subprocess.CalledProcessError: Command '['sudo', 'restrict_groupadd.sh', '0', 'toasteruser']' returned non-zero exit status 1
Make sure the /opt/yocto/docker-toaster directory was created before running Docker and is not owned by root. If you don't create it beforehand, Docker will do it with the root user and the setup will fail as above.
See https://github.com/crops/poky-container/issues/20.
Note
Note that you can replace the 127.0.0.1 above with an IP address that is externally accessible if you are running Docker on a different machine.
- You can now detach from the
dockercontainer with Ctrl + P Ctrl + Q. Check the container is still running with:
$ docker ps- You can now access the Toaster web interface at
http://127.0.0.1:18000. - The
dockercontainer can be stopped with the following command:
$ docker stop <container-id>See also
- Django documentation can be accessed at https://docs.djangoproject.com/en/1.9/
- The Django management command available at
toaster/manage.pyis documented as part of the Django documentation at https://docs.djangoproject.com/en/1.9/ref/django-admin/ - Docker specific documentation can be accessed at https://docs.docker.com/engine/reference/commandline/dockerd/
- The Toaster
dockercontainer home page is https://github.com/crops/toaster-container