This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
doc:docker [2015/04/26 12:16] stwn updates |
doc:docker [2015/05/08 10:41] (current) stwn [Creating Custom Docker Image] minor fix |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| * Packages installed: debootstrap and friends. | * Packages installed: debootstrap and friends. | ||
| - | * I use Debian testing/jessie (now stable), and put sid into sources.list so I can apt-get install docker.io, because docker.io [[https://packages.qa.debian.org/d/docker.io/news/20150331T163915Z.html|removed from testing]] in late March 2015 and available only in sid. | + | * I use Debian testing/jessie (now stable), and put sid into sources.list so I can apt-get install docker.io, because docker.io [[https://packages.qa.debian.org/d/docker.io/news/20150331T163915Z.html|removed from testing]] in late March 2015 and available only in sid.<code># vim /etc/apt/sources.list</code><code>deb http://yourrepo/debian/ sid main</code> |
| - | * Update your packages list<code># apt-get update</code> | + | * Update your packages list.<code># apt-get update</code> |
| * Install docker.io with:<code># apt-get install docker.io</code> | * Install docker.io with:<code># apt-get install docker.io</code> | ||
| - | ===== Creating Docker Image ===== | + | ===== Creating Minimal Base Docker Image ===== |
| - | * Use mkimage.sh to create Docker image<code>$ sudo /usr/share/docker.io/contrib/mkimage.sh -t ${USER}/minbase debootstrap --variant=minbase jessie http://yourrepo/debian/</code> | + | * Use mkimage.sh to create Docker image.<code>$ sudo /usr/share/docker.io/contrib/mkimage.sh -t ${USER}/minbase debootstrap --variant=minbase --components=main --include=inetutils-ping,inetutils-traceroute,iproute jessie http://yourrepo/debian/</code> |
| - | * Try to run 'echo'<code>$ sudo docker run -i ${USER}/minbase echo "hello citra"</code> | + | * Try to run 'echo':<code>$ sudo docker run -it ${USER}/minbase echo "hello citra"</code>or bash shell:<code>$ sudo docker run -it ${USER}/minbase /bin/bash</code> |
| - | ===== Creating Docker Container ===== | + | ===== Creating Custom Docker Image ===== |
| - | * First, create a dockerfile for your container. | + | * Firstly, create a dockerfile for your container.<code>$ vim dockerfile</code><code>FROM stwn/minbase |
| + | MAINTAINER stwn@NOSPAMduniasemu.org | ||
| + | RUN apt-get update && apt-get install -y \ | ||
| + | apt-utils less sudo screen \ | ||
| + | openssh-server openssh-client \ | ||
| + | asterisk</code> | ||
| + | * Build docker container based on the dockerfile.<code># docker build -t ${USER}/asterisk:test0 - < dockerfile</code> | ||
| ===== Frequently Used Commands ===== | ===== Frequently Used Commands ===== | ||
| + | * Restart docker service with systemd:<code># systemctl restart docker.service</code> | ||
| * Show images:<code># docker images | * Show images:<code># docker images | ||
| REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | ||
| stwn/minbase latest d816657c5182 3 minutes ago 123.7 MB | stwn/minbase latest d816657c5182 3 minutes ago 123.7 MB | ||
| scratch latest 511136ea3c5a 22 months ago 0 B</code> | scratch latest 511136ea3c5a 22 months ago 0 B</code> | ||
| - | * Show all running containers: <code># docker ps -a</code> | + | * Remove image:<code># docker rmi [IMAGE ID]</code> |
| - | * Remove image: <code># docker rmi <image></code> | + | * Commit change:<code># docker commit [IMAGE ID] ${USER}/asterisk:test1</code> |
| + | * Show all running containers:<code># docker ps -a</code> | ||
| + | * Remove container:<code># docker rm [CONTAINER ID]</code> | ||
| + | |||
| + | ===== Networking in Docker ===== | ||
| + | There is a network interface named docker0 when we run Docker engine. This interface connected as a (virtual Ethernet) bridge to containers inside Docker and configured with private ip address/network. | ||