Docker is a platform for developers and sysadmins to develop, ship, and run applications. It's created in the early of 2013 and based on Linux container LXC.
Docker makes things easy and convienent:
Docker consists of:
Please refer to Docker Installation. Here just gives some guide for Arch Linux.
Install docker package in community:
$ sudo pacman -S docker
Start docker
$ sudo systemctl start docker
To start on system boot:
$ sudo systemctl enable docker
If you want to make customizations on daemon options, please refer to customize your systemd Docker daemon options.
Creating an account
$ sudo docker login
Docker provides ability to run applictions inside containers. Run an application with command docker run
.
Say 'Hello world' to docker:
$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'
Hello world
This command may take some time to download the docker image at first time. ubuntu:14.04
is the image which is the container we ran. Docker looks for the image on your Docker host first. If the image is not found, it will be downloaded from Docker Hub.
Finally, docker executes command /bin/echo 'Hello world'
inside the container we launched.
This time we try a new commmand:
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
root@609bc7a62c87:/#
Here adds two options to docker run
:
Let's execute some commands:
root@609bc7a62c87:/# cat /etc/issue
Ubuntu 14.04.1 LTS \n \l
root@609bc7a62c87:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@609bc7a62c87:/# exit
Now create a container running as a daemon:
$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
c01af8ac6ed3cb0f314f82806feaf23ac8b8fc232a2a0c8286878768b4f7af5e
The -d
tells docker to run the container in the backgroud. And docker returns a long string which is a container ID.
We can query Docker daemon with docker ps
:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c01af8ac6ed3 ubuntu:14.04 "/bin/sh -c 'while t 9 minutes ago Up 8 minutes distracted_nobel
See output using docker logs
command with the name assigned automatically by docker:
$ sudo docker logs distracted_nobel
hello world
hello world
hello world
...