Docker Getting Started combat-ssh connecting Docker containers

Source: Internet
Author: User
Tags commit unique id ssh centos ssh server docker hub docker run
Introduction What is Docker

Docker is an open source project that was born in early 2013 and was originally an amateur project within the DotCloud company. It is based on Google's launch of the Go language implementation. The project later joined the Linux Foundation and complied with the Apache 2.0 protocol, and the project code was maintained on GitHub.

Docker has been widely watched and discussed since open source, so that DotCloud company later changed its name to Docker INC. Redhat has focused on supporting Docker;google in its RHEL6.5 and is also widely used in its PaaS products.

The goal of the Docker project is to implement a lightweight operating system virtualization solution. Docker is based on technologies such as Linux containers (LXC).

On the basis of LXC, Docker has been further encapsulated, so that users do not need to care about the management of containers, making the operation easier. User-operated Docker containers are as simple as operating a fast, lightweight virtual machine.

The image below compares the differences between Docker and traditional virtualization, where the container is virtualized at the operating system level, directly reusing the local host's operating system, while the traditional approach is implemented at the hardware level.

Why do you use Docker

As an emerging virtualization approach, Docker has a number of advantages over traditional virtualization approaches.

First, the launch of the Docker container can be implemented in seconds, which is much faster than the traditional virtual machine approach. Second, Docker is highly utilized for system resources and can run thousands of Docker containers simultaneously on a single host.

In addition to running applications, the container does not consume any additional system resources, which makes the performance of the application very high and the overhead of the system as small as possible. Traditional virtual machines run 10 different applications with 10 virtual machines, and Docker only needs to start 10 isolated applications.

Specifically, Docker has a big advantage in the following areas. Faster delivery and deployment

for development and operations (DEVOP) personnel, the most desirable is to create or configure one at a time, which can be run anywhere.

Developers can use a standard image to build a set of development containers that, when developed, can be used directly by the OPS to deploy the code. Docker can quickly create containers, quickly iterate applications, and make the entire process visible, making it easier for other members of the team to understand how the application was created and worked. Docker containers are very light and fast. The start time of the container is second-level, which saves the time of development, testing and deployment greatly. more efficient Virtualization

The Docker container runs without additional hypervisor support, which is a kernel-level virtualization that enables higher performance and efficiency. easier migrations and extensions

Docker containers can run on virtually any platform, including physical machines, virtual machines, public clouds, private clouds, personal computers, servers, and more. This compatibility allows the user to migrate an application directly from one platform to another. more Simple Management

With Docker, you can replace a lot of previous updates with just a little bit of modification. All modifications are distributed and updated incrementally, enabling automation and efficient management. Compare traditional virtual machine summaries

features Container Virtual Machines
Start Second level Minutes is
Hard disk use is generally MB typically GB
Performance Close to native Weaker than
System Support Volume Stand-alone support for thousands of containers Dozens of general
Installing Docker

It was intended to install Docker on the CentOS6, and eventually abandoned the Docker boot failure due to the low kernel version on CENTOS6 (kernel upgrade was cumbersome).

The following uses CentOS7 to install Docker, I use virtual machine to install, installed virtual machine must be able to access the extranet.

The CENTOS7 system has Docker in the Centos-extras library and can be installed directly:

$ sudo yum install Docker

Start the Docker service after installation and have it automatically loaded with the system boot:

$ sudo service docker start
$ sudo chkconfig docker on
Get Mirror

You can use the Docker pull command to get the required mirrors from the warehouse.

The following example downloads a Centos6 from the Docker Hub repository and installs the JDK7 image:

$ Docker Pull Tcbenkhard/centos6-jdk7

list local Mirrors

Use Docker images to display a local image.

$ docker Images

Start Container

There are two ways to start a container, one is to create a new container based on the mirror and start, and the other is to restart the container in the terminating state (stopped).

Because Docker containers are too lightweight, many times users are deleting and creating new containers at any time.
The following command launches a bash terminal that allows the user to interact.

$ docker run-t-i docker.io/tcbenkhard/centos6-jdk7/bin/bash
[root@ffe81683c404/]#

Where the-t option allows Docker to assign a pseudo-terminal (Pseudo-tty) and bind to the container's standard input,-I keeps the container's standard input open.

When you use Docker run to create a container, the standard operations that Docker runs in the background include:
(1) Check if there is a specified image locally and download it from the public repository if it does not exist
(2) Create and start a container with mirroring
(3) Assigning a file system and mounting a layer of read-write layers outside the mirrored layer
(4) Bridging a virtual interface into a container from the bridge interface configured by the host host
(5) Configure an IP address from the address pool to the container
(6) Execute user-specified application
(7) The container is terminated after completion of execution

You can use the following command to view the CentOS version information:

$ cat/etc/redhat-release
Change root password

Use the passwd password to modify the password (such as prompt without this command line using the Yum install passwd installation):

$ passwd
    xxx password
    xxx Confirm password
Installing OpenSSH

Install the SSH SERVER/SSH client using the following command:

$ sudo yum-y install openssh-server
$ sudo yum-y install openssh-clients

Modify the following options for the SSH configuration file, remove the # comment and enable the four options:

$ vi/etc/ssh/sshd_config

rsaauthentication Yes #启用 RSA certified
pubkeyauthentication Yes #启用公钥私钥配对认证方式
Authorizedkeysfile. Ssh/authorized_keys #公钥文件路径 (same as the file generated above)
Permitrootlogin Yes #root能使用ssh登录

Restart the SSH service and set the boot up:

$ service sshd Restart
$ chkconfig sshd on
exit the container and save the changes

Use the exit command or CTRL + C to exit the currently running container:

[Root@ffe81683c404/]# exit

Note: The above ffe81683c404 is the ID of the container and the unique ID used to save after exiting.

When this is over, we use Exit to exit, and now our container has been changed by us, using the Docker commit command to submit the updated copy.

$ sudo docker commit-m ' Install OpenSSH '-a ' docker Newbee ' ffe81683c404  centos6-jdk7:ssh
4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c

Where-M to specify the description of the submission, as we use the version Control tool;-A can specify updated user information, followed by the ID of the container used to create the mirror, and finally specify the warehouse name and tag information for the target image. The ID information for this image is returned when the creation is successful.

After submission, Docker will have one more centos6-jdk7:ssh image.
start a new container and get through Port 22

Start the new mirror and map port 50001 of the Docker server to port 22 on the container:

$ docker run-d-P 50001:22 centos6-jdk7:ssh/usr/sbin/sshd-d

SSH Connection container:

This SSH connection to the Docker container completed successfully. reference http://dockerpool.com/static/books/docker_practice/introduction/README.html/HTTP/ Blog.sina.com.cn/s/blog_600e56a60102vwjc.html

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.