ssh -i workshop.pem [email protected]
Replace 01
in lxc-1-01
with index assigned to you. Download workshop key below.
Become root
user via sudo -i
and execute following commands:
echo 'deb https://get.docker.io/ubuntu docker main' \
> /etc/apt/sources.list.d/docker.list
# optionally, trust the repo key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
--recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
apt-get update
apt-get install -y lxc-docker
usermod -a -G docker ubuntu
Re-login or su - ubuntu
for ubuntu
user to receive supplementary docker
group.
Update to patched 3.13 kernel on Precise:
apt-get install linux-hwe-generic
and reboot.
Other Linux distributions please follow the official instructions.
Public images are hosted on Docker Hub Registry. The sources of those images are usually found on GitHub, most notable repositories are:
docker pull centos:latest
docker pull phusion/baseimage:latest
docker images
Make sure to use :latest!
Via local Wi-Fi:
wget -O - http://192.168.1.3/docker/centos.tar.gz \
| gzip -dc \
| docker load
wget -O - http://192.168.1.3/docker/phusion-baseimage.tar.gz | gzip -dc | docker load
In the cloud:
wget -O - http://lxc-1-00.eu.r53.acp.io/docker/centos.tar.gz | gzip -dc | docker load
wget -O - http://lxc-1-00.eu.r53.acp.io/docker/phusion-baseimage.tar.gz | gzip -dc | docker load
Or ask me for a flash-drive.
There are more images to pull that we will need later: registry
, konradkleine/docker-registry-frontend
.
docker run -ti --rm centos /bin/bash
# in the container
ps auxw
df -h
exit
Let create our first Dockerfile
!
mkdir mine-service && cd mine-service
cat > Dockerfile <<EOF
FROM centos:latest
ADD run.sh /
CMD [ "/run.sh" ]
EOF
Create run.sh
:
echo -e '#!/bin/sh\necho Hello World!' > run.sh
chmod +x run.sh
Build the image and play around:
docker build .
docker images -a
# tag the latest image by CREATED column
docker tag c6dc2598a3c1 mine/service:devel
docker images -a
docker run --rm mine/service:devel
docker rmi mine/service:devel
Single-process container has some problems explained by Phusion people on phusion/baseimage website. You may want to read an alternative opinion.
Let rebase to phusion/baseimage and tell supervisor to monitor our process:
FROM phusion/baseimage:0.9.15
MAINTAINER Name <email>
ADD run.sh /etc/service/hello/run
RUN groupadd -r hello \
&& useradd -r -g hello hello
VOLUME /data
Modify run.sh
:
#!/bin/sh
u=hello:hello
chown $u /data
exec chpst -u $u /bin/sh -c "for i in 1 2 3 4 5; do echo Hello ${HELLO_OPTIONS:-World}! -- \$i; sleep 3; done; date >/data/date.txt"
Try it!
docker build -t mine/service:devel .
docker run --name hello -ti \
-e HELLO_OPTIONS="Docker World" \
-v /tmp:/data \
mine/service:devel \
/sbin/my_init -- bash -l
# in the container
ps auxw
exit
docker ps -a
docker rm hello
docker rmi mine/service:devel
cat /tmp/date.txt
ls -l /tmp/date.txt # notice owner of the file
More phusion/baseimage examples:
You may be also interested in ubuntu-upstart and fedora/systemd-systemd.
Signup for Docker Hub access. Then login and push the image:
docker login
docker build -t user/service:1.0.0 .
docker tag user/service:1.0.0 user/service:latest
docker push user/service
mkdir /tmp/registry
docker run --name registry -p 5000:5000 -v /tmp/registry:/tmp/registry \
-e SETTINGS_FLAVOR=local \
-e SEARCH_BACKEND=sqlalchemy \
registry
More usage info at Registry repository.
Let push some image into it, in another terminal:
docker tag user/service localhost:5000/service
docker push localhost:5000/service
ls -l /tmp/registry/*
Pull it back and run:
docker images
docker rmi localhost:5000/service user/service user/service:1.0.0
docker pull localhost:5000/service
docker run --rm localhost:5000/service
Let add an UI to our registry:
docker run --name registry-front -P \
-e ENV_DOCKER_REGISTRY_HOST=lxc-1-01.eu.r53.acp.io \
-e ENV_DOCKER_REGISTRY_PORT=5000 \
konradkleine/docker-registry-frontend
docker port registry-front 80
For the 0.0.0.0:49153
output of port
command, go and open http://lxc-1-01.eu.r53.acp.io:49153/
in the browser.
There is also another UI available:
docker inspect registry | grep IPAddress # got 172.17.0.2
docker run --name registry-ui -p 80:8080 \
-e REG1=http://172.17.0.2:5000/v1/ \
atcol/docker-registry-ui
Become root
, then:
apt-add-repository ppa:ubuntu-lxc/stable
apt-get update
apt-get install -y lxc lxc-templates cgmanager cgroup-lite cloud-utils
Remember to update kernel to 3.13+.
Check /etc/lxc/default.conf
to contain:
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
(The above is Ubuntu default)
Enable Promiscuous Mode in VirtualBox.
lxc-create -n test -t ubuntu-cloud \
-- -r precise -s daily # optional, use 12.04 with latest updates
# add
# -T https://cloud-images.ubuntu.com/precise/20141015/precise-server-cloudimg-amd64-root.tar.gz
# in case lxc-create cannot find ubuntu-cloudimg-query or do
# apt-get install cloud-utils
lxc-start -n test -d
lxc-ls -f
lxc-attach -n test
# in the container
ping google.com
ip addr ls dev eth0
ps auxw
exit
lxc-destroy -n test -f
Look for OS templates in /usr/share/lxc/templates/
.
More LXC examples:
- GitLab in Ubuntu container on Ubuntu and openSUSE hosts
- Stéphane Graber's LXC 1.0: Blog post series
Usefull: