Installing Docker under Ubuntu
Copy from http://www.cnblogs.com/linjiqin/p/3625609.html for easy viewing.
Docker is the open Source engine that DotCloud announced in recent months to provide an automated deployment solution for applications, simply by creating a container (like a virtual machine) on a Linux system and deploying and running applications on the container. Configuration files make it easy to automate installation, deployment, and upgrades of your applications. Because of the use of containers, it can be very convenient to the production environment and development environment, independent of each other, this is the most common Docker play. More gameplay also include large-scale Web applications, database deployment, continuous deployment, clustering, test environments, service-oriented cloud computing, virtual desktop VDI, and more.
Note: Since Docker needs to be in Linux Kernel 3.8 and above to be able to work very well "I ubuntu12.04 lts kernel 3.2 is also normal installation", the official is recommended Ubuntu system, here are two options: Ubuntu 12.04 Lts or the latest Ubuntu 13.10 and this article prefers LTS, fortunately there are ways to solve the kernel version problem.
1. Update the 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, restart your computer and check to see if the kernel has been successfully updated by the command "Uname-r".
2, Installation Lxc-docker
[Email protected]: sudo apt-get install software-properties-common #增加 add-apt-repository command
[Email protected]: sudo apt-get install python-software-properties
[Email protected]: sudo add-apt-repository ppa:dotcloud/lxc-docker #增加一个ppa源, such as: Ppa:user/ppa-name
[Email protected]: sudo apt-get update #更新系统
[Email protected]: sudo apt-get install Lxc-docker
3. Test whether the Doctor is installed successfully
[Email protected]:~# 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 Tousea self-sufficient runtime For Linux containers ....
4. Hello World
4.1. Download the official Ubuntu image
[Email protected]:~$ sudo docker pull Ubuntu #pull命令需要到国外的镜像仓库, pulling the mirror, because of the GFW relationship, the likelihood of pull failure is great
4.2. Run Hello World
[Email protected]:~$ sudo docker run Ubuntu/bin/echo Hello World
5. Common Docker commands
5.1, docker three kinds of command operation mode
Docker has three ways to run commands: ephemeral, interactive, daemon.
A, short-term: is just the "Hello World", the command after the execution, container terminated, but did not disappear, you can use sudo docker ps-a look at all the container, the first is just executed container, You can do it again:
[Email protected]:~$ sudo docker start container_id
But this time I can not see "Hello World", only see the ID, with the logs command can be seen:
[Email protected]:~$ sudo docker logs container_id
You can see two "Hello World" because this container runs two times.
B, interactive mode
[Email protected]:~$ sudo docker run-i-T Image_name/bin/bash #image_name为docker镜像名称
C, Daemon Way
That is, let the software run as a long time service, this is the SaaS Ah!
For example, an infinite loop of printed scripts (replaced by memcached, Apache, etc.), the operation method is still the same! ):
[Email protected]:~$ container_id=$ (sudo docker run-d ubuntu/bin/sh-c "while true; do echo Hello world; Sleep 1; Done ")
View its output outside of the container
[Email protected]:~$ sudo docker logs $CONTAINER _id
or connect to the container in real-time view
[Email protected]:~$ sudo docker attach $CONTAINER _id
Terminate container
[Email protected]:~$ sudo docker stop $CONTAINER _id
[Email protected]:~$ sudo docker PS #看一下, no more
5.2. Docker PS command
[Email protected]:~$ sudo docker PS #列出当前所有正在运行的container
[Email protected]:~$ sudo docker ps-l #列出最近一次启动的, and running container
[Email protected]:~$ sudo docker ps-a #列出所有的container
Attention:
A. For other usage please refer to sudo docker ps-h
B, there is also a way to let the program run in daemon mode, that is, in the Dockerfile set user to Daemon
5.3. Docker Export Command
[Email protected]:~$ container_id= ' docker run-d <image_name> ls '
[Email protected]:~$ docker export $container _id > Image.tgz
5.4. Docker Import Command
[Email protected]:~$ cat Image.tgz | sudo docker Import-simple_dev #simple_dev为自定义的镜像名称
5.5. Docker Port Command
[Email protected]:~$ docker run-p 80:8080 <image> <cmd> #映射容器的8080端口到宿主机的80端口
5.6. Delete Container
5.6.1, delete all containers
[Email protected]:~$ sudo docker rm ' sudo docker ps-a-Q '
5.6.1, deleting a specific container
[Email protected]:~$ sudo docker rm $CONTAINER _id
5.7. Quick reference of Docker command
[email protected]:~$ sudo docker images #查看本地镜像
[Email protected]:~$ sudo docker attach $CONTAINER _id #启动一个已存在的docker实例
[Email protected]:~$ sudo docker stop $CONTAINER _id #停止docker实例
[Email protected]:~$ sudo docker logs $CONTAINER _id #查看docker实例运行日志 to ensure normal operation
[Email protected]:~$ sudo docker inspect $CONTAINER _id #查看container的实例属性, such as IP, etc.
sudo docker run-t-i-v/home/linjiqin/dev/docker:/home/mycontainer:rw-p 8000:8000 Mydocker/bin/bash
Written in front, the command that runs our image uses the above as a reference, which mounts the local folder and maps the container 8000 port to the host's 8000 port
/home/linjiqin/dev/docker is a local folder to mount, you need to create it in advance
/home/mycontainer is the Docker mapping path, executing the above command will help us create
Category: Ubuntu
Installing Docker under Ubuntu