Quickie on Docker

For those of you who don’t know, Docker is a way to have isolated applications that are able to be sent to various OS while being agnostic of that OS.

It has the advantage of chroot in that chroot is bound to a local machine.

This is a great oppertunity for me, because for each individual application, I tend to create a whole new VM. This is very wasteful, because I’ll have seven instances of CentOS and the software is 99% the same, but they don’t share any of that data so I’m just burning disk space on my ZFS server.

I did this isolation so that should one server be compromised then my entire network isn’t hosed. The idea of isolation is still something that we’re going to go with, but I don’t want to waste extra disk space.

For openSuSE, the install is very simple:


zypper in docker docker-compose docker-test yast2-docker
#Start and make sure that process always runs.
systemctl enable docker
systemctl start docker

Note, that I’ve added some extra stuff that should make things easy for beginners 😉

Now, as root, let’s make sure everything is good:


docker run hello-world

And everything should work!


Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

This is cool and all, but logging yourself in as root (or sudoing) is always the safest idea just to run a program. To remedy this:


usermod -aG docker $USER #substitute for your username here

Log out and back in (or from your user terminal just run su – $USER)

To build my own custom image, I’ll need some sort of base system. From Docker documentation , it looks like it’ll work just fine with chroot base systems (this is great if you’re converting from a chroot to Docker)!

Because I use OpenSuSE and there isn’t an official boot strap (but there is one for Debian in the repos oddly enough), we should build our own chroot and then convert it over.

I found this handy guide on creating a OpenSuSE chroot.

So, let’s just get right into it! As root:


mkdir -p /chroot/opensuse-42.2
zypper --root /chroot/opensuse42.2 ar http://download.opensuse.org/distribution/leap/42.2/repo/oss/ repo-oss
#Note, I got the above by doing zypper lr -u and grabbing the URI from there so if you're using a new repo you can get the right data
mkdir -p /chroot/opensuse-42.2/dev
cp -av /dev/zero /chroot/opensuse-42.2/dev/
zypper --root /chroot/opensuse-42.2/ install rpm zypper wget vim
#At this point, you can chroot into it and make some tweaks (chroot /chroot/opensuse42.2)
#Once you're done, we'll tar it up and send it to docker!
cd /chroot
tar -C opensuse-42.2 -c . | docker import - opensuse42.2
docker run opensuse-42.2 cat /etc/*release

And there you have it! If I need to make any major updates then I’ll link back and forth, but this should be enough of a start to get you going.

EDIT: 2017/04/27 Added a p id for linking goodness.

This entry was posted in Computer Science and tagged , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.