7
How to build a headless Ubuntu / XFCE with Docker & Dockerfish Make sure you have Docker installed first and foremost. Getting started This tutorial demonstrates the ease of use of my tool Dockerfish which i coded from the ground up in pure Ruby it requires no gems so there is no messing about. I also show you then how make a image from your container with ease also. All you have todo is have git installed and most developers have it installed as a no brainer. if not apt-get install git for Ubuntu / Debian or yum install git for Centos / Fedora etc ... cd into the folder of your choice to download into then. git clone https://github.com/puppetpies/DockerFish-CLI.git Check if docker is running systemctl status docker.service docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled) Active: active (running) since Fri 2015-06-26 10:21:28 BST; 46min ago Docs: http://docs.docker.io Process: 786 ExecStartPre=/usr/bin/mount --make-rprivate / (code=exited, status=0/SUCCESS) Main PID: 792 (docker) CGroup: /system.slice/docker.service 792 /usr/bin/docker --api-enable-cors=true -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -d Making sure the API is enabled your docker.service ExecStart line should look like this. -H tcp://0.0.0.0:2375 - You may want to restrict this to certain interface / ip address as this what DockerFish will access the API via. cat /etc/systemd/system/multi-user.target.wants/docker.service [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.io After=network.target [Service]

Dockerfish-Tutorial

Embed Size (px)

Citation preview

Page 1: Dockerfish-Tutorial

How to build a headless Ubuntu / XFCE with Docker & Dockerfish

Make sure you have Docker installed first and foremost.

Getting started

This tutorial demonstrates the ease of use of my tool Dockerfish which i coded from the ground up in pure Ruby it requires no gems so there is no messing about.

I also show you then how make a image from your container with ease also.

All you have todo is have git installed and most developers have it installed as a no brainer.

if not apt-get install git for Ubuntu / Debian or yum install git for Centos / Fedora etc ...

cd into the folder of your choice to download into then.

git clone https://github.com/puppetpies/DockerFish-CLI.git

Check if docker is running

systemctl status docker.servicedocker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled) Active: active (running) since Fri 2015-06-26 10:21:28 BST; 46min ago Docs: http://docs.docker.io Process: 786 ExecStartPre=/usr/bin/mount --make-rprivate / (code=exited, status=0/SUCCESS) Main PID: 792 (docker) CGroup: /system.slice/docker.service 792 /usr/bin/docker --api-enable-cors=true -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -d

Making sure the API is enabled your docker.service ExecStart line should look like this.

-H tcp://0.0.0.0:2375 - You may want to restrict this to certain interface / ip address as this what DockerFish will access the API via.

cat /etc/systemd/system/multi-user.target.wants/docker.service [Unit]Description=Docker Application Container EngineDocumentation=http://docs.docker.ioAfter=network.target

[Service]ExecStartPre=/usr/bin/mount --make-rprivate /ExecStart=/usr/bin/docker --api-enable-cors=true -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -d

[Install]WantedBy=multi-user.target

If you have had to make changes to this file then do the below.

systemctl daemon-reload

Then restart Docker where convieniant.

systemctl restart docker.service

Page 2: Dockerfish-Tutorial

Now check if Docker has started up correctly systemctl status docker.service if all is well lets download Ubuntu.

docker pull ubuntu

This may take sometime but its worth the wait.

Introduction to Dockerfish

Make your dockerfish.rb executable

chmod 755 dockerfish.rb

symlink to /usr/bin # You need root for this and optional ln -s dockerfish.rb /usr/bin/dockerfish./dockerfish.rb

Welcome to DockerFish Version 0.1---------------------------------Interactive CLI Docker Interface[] | | ,|. ,|/. ,' .V. `. / . . /_` |@)| . . |(@| ,-._ `._'; . :`_,' _,-. '-- `- /,-===-. /-' --` (---- _| ||___|| |_ ----) `._,-' `-.-' / `-._,' `-.___,-' ap[]

TIPS: Please note ContainerId's / Names are interchangeableYou can also use short ContainerId's as long as there is a unique matchStart with Docker API Enabled: /usr/bin/docker --api-enable-cors=true -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -dAdd a symlink ln -s /home/brian/Projects/DockerFish/dockerfish.rb /usr/bin/dockerfish

--help # For more information

Enjoy!

Coded by Brian HoodServer Info:

{"ApiVersion"=>"1.18", "Arch"=>"amd64", "GitCommit"=>"a61716e", "GoVersion"=>"go1.4.2", "KernelVersion"=>"3.14.5-1-ARCH", "Os"=>"linux", "Version"=>"1.5.0-dev"}DockerFish> 1

List of Docker Images ===================== Created: 2015-06-12 16:32:30 Id: 6d4946999d4fb403f4 Image: ["ubuntu:latest"] Size: 8B VirtualSize: 179.563MB

You now have the latest Ubuntu image at your finger tips great so what now ?

The first step is press 6 and hit enter.

Page 3: Dockerfish-Tutorial

6) Create Container from Image

Enter Image to use> ubuntu:latestExample: name or name1,name2,name3Enter Container name(s)> ubuntu-xfce-headless{ "Hostname":"ubuntu-xfce-headless", "User":"", "Memory":0, "MemorySwap":0, "CpuShares":0, "AttachStdin":true, "AttachStdout":true, "AttachStderr":true, "PortSpecs":null, "Tty":true, "OpenStdin":true, "StdinOnce":true, "Env":null, "Cmd":[ "/bin/bash" ], "Dns":null, "Image":"ubuntu:latest", "VolumesFrom":"", "WorkingDir":"", "HostConfig": { "NetworkMode": "bridge", "Devices": [] }}Container Creation Successfull DockerFish> 2

List of Docker Containers =========================

Command: /bin/bash ContainerId: 5073abe5f5c9 Image: ubuntu:latest Names: ["/ubuntu-xfce-headless"] Status:

Ok lets start up your container.

Press 3

DockerFish> 3

Enter Container to Start> ubuntu-xfce-headlessStarting Container ubuntu-xfce-headless Start Successfull DockerFish> 2

List of Docker Containers =========================

Command: /bin/bash ContainerId: 5073abe5f5c9 Image: ubuntu:latest Names: ["/ubuntu-xfce-headless"] Status: Up 48 seconds

Was it really that easy to yes in short now you just have todo the configuration in the next step.

Build your machine from scratch

Startup and Terminal

To attach to your docker instance run the folllowing.

docker attach ubuntu-xfce-headless

Page 4: Dockerfish-Tutorial

Then hit enter again to enter the container.

[brian@orville ~]$ docker attach ubuntu-xfce-headlessroot@ubuntu-xfce-headless:/# apt-get updateIgn http://archive.ubuntu.com trusty InReleaseIgn http://archive.ubuntu.com trusty-updates InReleaseIgn http://archive.ubuntu.com trusty-security InReleaseHit http://archive.ubuntu.com trusty Release.gpgGet:1 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]Get:2 http://archive.ubuntu.com trusty-security Release.gpg [933 B]-- OMITTED --

Ok so you obtained the latest Ubuntu repository data if you don’t know what the means don’t worry.

Next download XFCE4

root@ubuntu-xfce-headless:/# apt-get install xfce4 xvfb x11vncReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following extra packages will be installed:

-- OMITTED LOTS OF PACKAGES --

2 upgraded, 384 newly installed, 0 to remove and 9 not upgraded.Need to get 94.4 MB of archives.After this operation, 378 MB of additional disk space will be used.Do you want to continue? [Y/n]

Press Y enter and sit back and relax read a book etc ...

Setup VNC / Xvfb

root@ubuntu-xfce-headless:/# mkdir ~/.vncroot@ubuntu-xfce-headless:/# x11vnc -storepasswd letmein ~/.vnc/passwdroot@ubuntu-xfce-headless:/# Xvfb :1 -extension GLX -screen 0 1024x780x24 &root@ubuntu-xfce-headless:/# DISPLAY=:1 /usr/bin/xfce4-session &root@ubuntu-xfce-headless:/# x11vnc -usepw -forever -display :1 &

cat > start_session.shXvfb :1 -extension GLX -screen 0 1024x780x24 &sleep 2DISPLAY=:1 /usr/bin/xfce4-session &sleep 2x11vnc -usepw -forever -display :1 &

Press CTRL+Cchmod 755 start_session.sh

When you start your Docker container you can now just go.

./start_session.sh

See what your Docker container IP is.

root@ubuntu-xfce-headless:/# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever5: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:01 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 scope global eth0

Page 5: Dockerfish-Tutorial

valid_lft forever preferred_lft forever inet6 fe80::42:acff:fe11:1/64 scope link valid_lft forever preferred_lft forever

Install a VNC Viewer like tigervnc on your host OS and connect to 172.17.0.1:0 this will default to port 5900 using display port 0

Everything now working !

I recommend that you go into your settings in XFCE and configure the appearance as i had no icons until i selected Tango from the icons menu.

Ok now as promised you have your Ubuntu with XFCE running under Docker.

Now lets make this container into its own Image so i can make as many of these as i want the question is how.

Thats easy.

First detach from your

root@ubuntu-xfce-headless:/# exit

Go back to your Dockerfish terminal.

DockerFish> 2

List of Docker Containers =========================

Command: /bin/bash ContainerId: 5073abe5f5c9 Image: ubuntu:latest Names: ["/ubuntu-xfce-headless"] Status: Exited (0) About a minute ago

You can see that it has exited which you need to create a image from it.

DockerFish> 15

Enter Container to Image> ubuntu-xfce-headlessEnter your commit comment important> Ubuntu XFCE HeadlessEnter your Repository name> devel/headless-ubuntu-vncImage Commit Successfull

How do i check if it worked ?

DockerFish> 1

List of Docker Images =====================

Created: 2015-06-26 13:14:16 Id: 97a9b89d37cf63b41e Image: ["devel/headless-ubuntu-vnc:latest"] Size: 501.381MB VirtualSize: 680.944MB

Now you’ve created your image your free to customize it by making more containers and making them into images.

Enjoy !

Brian Hood

Page 6: Dockerfish-Tutorial