Docker examples
Dockerfile Workflow (Simple)
The core idea here is that you are building an image (program environment) that you can later run programs within.
Dockerfile
FROM ubuntu:16.04 RUN apt-get update RUN apt-get install -y python3 python3-pip python3-dev RUN python3 -m pip install wheel RUN python3 -m pip install ipythonbuild/run
sudo docker build . -f Dockerfile -t test_image # build a new image sudo docker images # you should see a new test_image there sudo docker run -ti test_image /bin/bash # create container, and interactively run your docker image ipython # (you can now interactively run apps in this container) sudo docker start test_image # run already created container sudo docker exec -ti bash test_image # interactive terminal in started container (can start as many as you'd like)
X11 Application Example
In order to run X11 applications from within docker, you'll need to share your X11 socket, and make sure that your user inside the container has permission to read/write to the X11 socket.
Depending on your X11 config, providing permissions might mean forwarding your
~/.Xauthority
file, or (as we are doing below) forwarding your passwd,shadow,group,and sudoers files with the container. The way this is set up, the root user in the container is mapped to the current user running the command on the host OS. All files in your homedir are shared this way. (sweet, right?!).
Dockerfile
#### Dockerfile (creates image) FROM centos:7.2.1511 RUN yum -y update && \ yum -y upgrade && \ yum -y install xorg-x11-server-Xorg `# xorg-server ` && \ yum -y install xorg-x11-xauth `# needed to use host's xorg ` && \ yum -y install xeyes `# test normal GUI app ` && \ yum -y install glx-utils `# test openGL/3Daccel apps `build image
Dockerfile (w/ opengl)
If you want to run a 3D-accelerated application within docker you will need to:* share the X11 socket using
--privileged
* install video drivers **matching the host**
* for intel this will be
mesa-dri-drivers
* for nvidia this will be nouveau, or the nvidia binary driver * for ati this will be#!/usr/bin/env bash ## launcher script (creates container) xhost local:root # allow user 'root' to use X11 socket sudo docker run \ --name maya2017 `# name of container` \ --hostname dockermaya \ -v /tmp/.X11-unix/X0:/tmp/.X11-unix/X0:rw --privileged `# share host's X11 socket` \ --device=/dev/dri:/dev/dri `# video card (only for opengl)` \ -e DISPLAY=unix$DISPLAY `# display to render to` \ -ti \ maya:2017.a1 exit # exit the containertest (after building container)
sudo docker start maya2017 # start in background sudo docker attach maya2017 # access console from container # (container stops on exit) xeyes # googly eyes should appear on your host glxgears # tests 3D-acceleration from within container glxinfo # info about 3D-acceleration in container
Interactive Container
You can use docker as a persistent VM if you'd like (ensuring your dev environment is reproducible). Just make sure that you are writing your information to a VOLUME mount, or else all of your changes will be lost when you exit the container.