Docker tossing notes with Chinese characteristics (I)

Source: Internet
Author: User
Tags virtualenv docker ps docker run linux mint

Introduction
In the past 2013, docker was undoubtedly a revolutionary innovation in O & M. However, in an Internet environment with Chinese characteristics, it was really inconvenient to make such a move.

Not to mention that the official docker. io website is hosted in the repository, including its apt source and image index. As a result, users have increased a lot of unnecessary costs, which is really a great pity for Chinese programmers. I really don't know why docker is a pure technology ......

So what exactly is docker?

First, you can think of docker as something similar to a virtual machine (VM). You can package the application you want to publish into a docker image and deploy it on the actual machine. This type of machine can be an actual server, VPS, or other PaaS. Then, in a machine environment, you can run several docker containers at the same time. The relationship between image and container can be understood as the relationship between "class" and "instance. In addition, the container running in a machine environment can also be based on different images. You can Package A iner into an image at any time for re-deployment.

The changes you make in a iner can also be updated to other container based on the same image. Because only modified parts can be updated, similar to updates under version control. There is also a local management warehouse (the east and west of the repositry.pdf), an official Warehouse (index.doc ker. io, equivalent to github) of docker.iov, or self-built (docker-registry ).

At last, it differs from VM in the following word: light. A vm actually contains a set of Virtual Hardware, a complete OS, and then an application. Docker iner is only an isolated application program running environment. For an application, the docker environment is equivalent to a complete OS, but it actually runs on the host OS, A container contains only the differences between the application environment and the host environment, which is very lightweight.

A more appropriate analogy is: virtualenv is similar to python. However, this is an OS-level virtualenv.

Install

According to the installation instructions in the official documents, it is best to use ubuntu 13.04 or later because the kernel version is later than 3.8. Other releases or earlier versions of ubuntu are neither good nor inconvenient. For other platforms, use the Vagrant Virtual Machine solution.

Because my own desktop is 12.04LTS, I am too reluctant to manually upgrade the kernel (the upgrade method is available in the official docker documentation), So I installed a VirtualBox virtual machine on the FreeBSD server, install Linux Mint 16 (based on ubuntu 13.10 ). The following is an example.

First, docker depends on aufs. Fortunately, this Mint comes with it. If it is another release or a manual kernel upgrade, check it:

sudo apt-get updatesudo apt-get install linux-image-extra-`uname -r`

The apt source of docker is added later.

Add the certificate before adding the source:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

However, because the official source is damaged by the wall, fortunately there is another image source available:

sudo sh -c "echo deb http://mirror.yandex.ru/mirrors/docker/ docker main\> /etc/apt/sources.list.d/docker.list"sudo apt-get updatesudo apt-get install lxc-docker

Now, the theoretical installation has been completed. But it cannot be used properly ......

Use

As mentioned above, the installation is complete and cannot be used normally. This is also caused by the shameful Greater China LAN, and the docker index Server is walled.

Solution: You need a VPN or an HTTP proxy (if there is a SOCK5 proxy, you can also use privoxy or polipo to convert it to an HTTP Proxy ).

If you have a VPN outside China, you can directly establish a VPN connection. Assume that you have an HTTP Proxy: proxy_server: 8118.

sudo service stop dockersudo HTTP_PROXY=http://proxy_server:8118 docker -d &

Now we can start using docker in the dark. Try:

sudo docker run -i -t ubuntu /bin/bash

As for how to use it, you can first try it on the official simulator, and then do it again in your real environment. You should have a practical experience.

Common commands:

# Search for imagedocker search [...] in the official repository # download the specified imagedocker pull [image] from the official repository # generate a iner from the specified image and run a command docker run [image] [cmd] # run the interactive command in the container, for example, shelldocker run-I-t [imag] [cmd] # run the background task docker run-d [image] [cmd] # in the container to list the latest running container, if-l is not added, only the running iner (such as the background task) is listed) docker ps-l # list all containerdocker ps-a # view the container details docker inspect [container_id] # delete a container. The container_id does not need to be completely entered, docker rm [container_id] # Run containerdocker start [container_id] # view the running log of a container docker logs [container_id] # Switch to the background task container. Note: after switching to the background task, you cannot use Ctrl-C to exit docker attach [container_id] # stop the background task containerdocker stop [container_id] # Save the container as an imagedocker commit [container_id] [image_name] # list imagesdocker images already exists in the current environment # upload the image to the repository docker push [image_name]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.