Docker is an open source engine just released by dotCloud in recent months. It is designed to provide an automatic deployment solution for applications. Simply put, it is very convenient to quickly create a container (similar to a virtual machine) on the Linux system, deploy and run applications on the container, and automatically install, deploy and upgrade applications through configuration files. Because of the use of containers, it is convenient to separate the production environment from the development environment without affecting each other, which is the most common gameplay of docker. More games include large-scale web applications, database deployment, continuous deployment, clustering, test environment, service-oriented cloud computing, virtual desktop VDI and so on.
Note: Docker needs Linux kernel 3.8 or above to work properly. I also installed it normally in ubuntu 12.04 lts kernel 3.2, and officially recommended ubuntu system. There are two choices here: Ubuntu 12.04 LTS or the latest Ubuntu 13. 10. This article prefers LTS. Fortunately, there is a way to solve the kernel version problem.
1, update Ubuntu kernel
Use the following command line to update the kernel to 3.8.0-25.
Install linux-image-3.8.0-25-generic.
Sudo apt-get installs Linux-headers-3. 8. 0-25- General.
Restart the computer after completion, and use the "uname -r" command to check whether the kernel is updated successfully.
2. install lxc-docker
Root @ Ubuntu: sudoapt-get installation software-properties -common # Add add-apt-repository command.
Root@ubuntu: sudo apt-get Install python- Software-Properties
Root @ Ubuntu: sudo add-apt-repository PPA: dotcloud/lxc-docker # Add a PPA source, such as ppa:user/ppa-name.
Root@ubuntu: sudo apt-get update # updates the system.
root @ Ubuntu:sudo apt-get install lxc-docker
3. Test whether doctor is successfully installed.
Root@ubuntu:~# docker # The following message shows that Docker was successfully installed.
Usage: docker [OPTIONS] command [arg...]
-h = [TCP:/127.0.0.1:4243]: TCP://host: the port to be bound/connected to or unix://path/to/socket used.
Self-sufficient runtime for linux containers.
...
hello, world
4. 1, download the official ubuntu image.
Linjiqin @ Ubuntu: ~ $ sudo docker pull Ubuntu # pull command needs to go to a foreign mirror warehouse to pull the mirror, because of GFW, the pull is likely to fail.
4.2. Run hello world
linji Qin @ Ubuntu:~ $ sudo docker run Ubuntu/bin/echo hello world
5.docker common commands
5. 1, docker three command operation modes
Docker has three command operation modes: transient mode, interactive mode and guardian mode.
A. Short-lived mode: it is just "hello world". After the command is executed, the container will terminate, but it will not disappear. You can use sudo docker ps -a to view all the containers. The first is the container that has just been executed. You can execute it again:
linji Qin @ Ubuntu:~ $ sudo docker start container _ id
But this time I can't see "hello world", I can only see the ID, and I can only see it with the logs command:
Linjiqin@ubuntu:~$ sudo docker log container_id
You can see two "hello world" because this container has been run twice.
B, interactive mode
Linjiqin @ Ubuntu: ~ $ sudo docker run-i-t image _ name/bin/bash # image _ name is the image name of docker.
C, guardian mode
That is to let the software run as a long-term service, which is SAAS!
Such as infinite loop print script (replaced by memcached, apache, etc. , the operation method remains the same! ):
linji Qin @ Ubuntu:~ $ CONTAINER _ ID = $(sudo docker run-d Ubuntu/bin/sh-c " while true; Do echo hello world sleep1; Finish ")
Look at its output outside the container.
linji Qin @ Ubuntu:~ $ sudo docker logs $ CONTAINER _ ID
Or connect to the container for real-time viewing.
linji Qin @ Ubuntu:~ $ sudo docker attach $ CONTAINER _ ID
Terminal container
linji Qin @ Ubuntu:~ $ sudo docker stop $ CONTAINER _ ID
Linjiqin @ Ubuntu: ~ $ sudo dockerps # Look, it's gone.
5.2.docker ps command
Linjiqin @ Ubuntu: ~ $ sudo dockerps # Lists all currently running containers.
Linjiqin @ Ubuntu: ~ $ sudo docker ps-l # lists the newly started and running containers.
Linjiqin @ Ubuntu: ~ $ sudo dockers ps-a # List all containers.
note:
A. for other usage, please refer to sudo docker ps -h H h.
B, there is another way to make the program run in daemon mode, that is, set the user as daemon in Dockerfile.
5.3. docker Export Command
linji Qin @ Ubuntu:~ $ container _ id = ` docker run-d & lt; image _ name & gtls ` 1
linji Qin @ Ubuntu:~ $ docker export $ container _ id & gt; image.tgz
5.4. docker import command
Linjiqin @ Ubuntu: ~ $ catimage.tgz | sudo docker import-simple _ dev # simple _ dev is a user-defined image name.
5.5. docker port command
linji Qin @ Ubuntu:~ $ docker run-p 80:8080 & lt; Image & gt& ltcmd & gt# maps port 8080 of the container to port 80 of the host.
5.6, delete the container
5.6. 1. Delete all containers.
linjiqin @ Ubuntu:~ $ sudo docker RM ` sudo docker PS-a-q '
5.6. 1. Delete a specific container.
linji Qin @ Ubuntu:~ $ sudo docker RM $ CONTAINER _ ID
5.7, docker command quick reference
Linjiqin @ Ubuntu: ~ $ sudo docker images # View local pictures
Linjiqin @ Ubuntu: ~ $ sudo docker attach $ container _ id # Start an existing docker instance.
Linjiqin @ Ubuntu: ~ $ sudo docker stop $ container _ id # Stop the docker instance
Linjiqin @ Ubuntu: ~ $ sudo dockerlogs $ container _ id # Check the docker instance running log to make sure it runs normally.
Linjiqin @ Ubuntu: ~ $ sudo docker inspect $ container _ id # View the instance properties of the container, such as ip and so on.
sudo docker run-t-I-v/home/linji Qin/dev/docker:/home/my container:rw-p 8000:8000 my docker/bin/bash
Written in front, the command to run our image uses the above as a reference, which will mount the local folder and map the 8000 port of the container to the 8000 port of the host.
/home/linjiqin/dev/docker is a local folder to be mounted and needs to be created in advance.
/home/mycontainer maps the path to docker, and executing the above command will help us create it.