Docker is an Open-source engine that DotCloud recently announced in recent months, designed to provide an automated deployment solution for an application, simply by quickly creating a container (like a virtual machine) on a Linux system and deploying and running the application on a container, And it's easy to automate installation, deployment, and upgrades of applications with configuration files. Because the use of containers, so can be very convenient to the production environment and development environment separate, not affect each other, this is the most common one of the Docker play. More games include large-scale Web applications, database deployments, ongoing deployments, clustering, test environments, service-oriented cloud computing, virtual desktop VDI, and more.
Note: because Docker need to be in the Linux Kernel 3.8 and above can be very good work "I ubuntu12.04 lts kernel 3.2 also normal installation", the official recommended Ubuntu system, here are two options: Ubuntu 12.04 Lts or the latest Ubuntu 13.10 and this article prefers to tend to lts, fortunately there are ways to solve the kernel version of the problem.
1. Update Ubuntu kernel
Use the following command line to update the kernel to 3.8.0-25
sudo apt-get install linux-image-3.8.0-25-generic
sudo apt-get install linux-headers-3.8.0-25-generic
When you are done, reboot your computer and check to see if the kernel has been successfully updated by the command "Uname-r".
2. Installation Lxc-docker
Root@ubuntu:sudo apt-get Install software-properties-common #增加 add-apt-repository command Root@ubuntu:sudo apt-get
Install python-software-properties
root@ubuntu:sudo add-apt-repository ppa:dotcloud/lxc-docker #增加一个ppa源, for example: PPA : User/ppa-name
root@ubuntu:sudo apt-get update #更新系统
root@ubuntu:sudo apt-get Install Lxc-docker
3. Test doctor whether the installation is successful
root@ubuntu:~# Docker #出现如下信息表示docker安装成功
usage:docker [OPTIONS] COMMAND [arg ...]
-H=[TCP://127.0.0.1:4243]: Tcp://host:port to Bind/connect to or unix://path/to/socket touse
A self-sufficient Runtime for Linux containers.
...
4, Hello World
4.1. Download the official Ubuntu image
linjiqin@ubuntu:~$ sudo docker pull Ubuntu #pull命令需要到国外的镜像仓库, pulling mirrors, because of the GFW relationship, the likelihood of pull failure is great
4.2. Run Hello World
linjiqin@ubuntu:~$ sudo docker run Ubuntu/bin/echo Hello World
5, Docker Common command
5.1, docker three kinds of command operation mode
Docker has three kinds of commands to run: Transient mode, interactive mode, daemon mode.
A, short way: is just that "Hello World", after the command execution, container terminated, but did not disappear, you can use sudo docker PS-
A look at all the container, the first is the container that you just performed, and you can do it again:
linjiqin@ubuntu:~$ sudo docker start container_id
But this time I do not see "Hello World", only to see the ID, with the logs command to see:
linjiqin@ubuntu:~$ sudo docker logs container_id
You can see two "Hello World" because this container runs two times.
B, interactive mode
linjiqin@ubuntu:~$ sudo docker run-i-T Image_name/bin/bash #image_name为docker镜像名称
C, Daemon Way
Let the software run as a long time service, that's SaaS!
For example, an infinite loop print script (replace with memcached, Apache, etc., the operation method is still the same!) ):
linjiqin@ubuntu:~$ container_id=$ (sudo docker run-d ubuntu/bin/sh-c "while true; do echo Hello world; Sleep 1; Done ")
View its output outside the container
linjiqin@ubuntu:~$ sudo docker logs $CONTAINER _id
Or connect the container in real time view
linjiqin@ubuntu:~$ sudo docker attach $CONTAINER _id
Terminate container
linjiqin@ubuntu:~$ sudo docker stop $CONTAINER _id
linjiqin@ubuntu:~$ sudo docker PS #看一下, it's gone.
5.2, Docker PS command
linjiqin@ubuntu:~$ sudo docker ps #列出当前所有正在运行的container
linjiqin@ubuntu:~$ sudo docker ps-l #列出最近一次启动的, and the running container
linjiqin@ubuntu:~$ sudo docker ps-a #列出所有的container
Attention:
A, other usage please refer to sudo docker ps-h
B, there is also a way to allow the program to run in daemon mode, that is, in Dockerfile set user as Daemon
5.3. Docker Export Order
linjiqin@ubuntu:~$ container_id= ' docker run-d <image_name> ls '
linjiqin@ubuntu:~$ Docker export $container _ ID > image.tgz
5.4. Docker Import Command
linjiqin@ubuntu:~$ Cat Image.tgz | sudo docker Import-simple_dev #simple_dev为自定义的镜像名称
5.5. Docker Port Command
linjiqin@ubuntu:~$ Docker run-p 80:8080 <image> <cmd> #映射容器的8080端口到宿主机的80端口
5.6, delete the container
5.6.1, remove all containers
linjiqin@ubuntu:~$ sudo docker rm ' sudo docker ps-a-Q '
5.6.1, delete a specific container
linjiqin@ubuntu:~$ sudo docker rm $CONTAINER _id
5.7, Docker Command Quick reference
linjiqin@ubuntu:~$ sudo docker images #查看本地镜像
linjiqin@ubuntu:~$ sudo docker attach $CONTAINER _id #启动一个已存在的docker实例
linjiqin@ubuntu:~$ sudo docker stop $CONTAINER _id #停止docker实例
linjiqin@ubuntu:~$ sudo docker logs $CONTAINER _ ID #查看docker实例运行日志 to ensure normal operation
linjiqin@ubuntu:~$ sudo docker inspect $CONTAINER _id #查看container的实例属性, such as IP and
sudo Docker run-t-i-v/home/linjiqin/dev/docker:/home/mycontainer:rw-p 8000:8000 Mydocker/bin/bash
Written in front, the commands running our mirrors use the above for reference, which will mount the local folder and map the container 8000 port to the host's 8000 port
/home/linjiqin/dev/docker for the local folder you want to mount, you need to create it in advance
/home/mycontainer is the Docker mapping path, and executing the above command will help us create
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.