Docker practice (1)-getting started

Source: Internet
Author: User
Tutorial

Centos6.5 environment.

# Yum install docker-io-y

Will depend on the installation of libcgroup, lxc, lxc-libs

 

Start docker

# Service docker start

Starting cgconfig service: [OK]

Starting docker: [OK]

 

Get the latest docker Image

# Docker pull centos: Latest

Run Image

# Docker run-I-t centos/bin/bash

Bash-4.2 # ls

Bin Dev etc home lib lib64 lost + found media MNT opt proc root run sbin SELinux SRV sys tmp usr VaR

Bash-4.2 # exit

 

Submit update

# Docker commit-M = "add net-Tools"-A = "dbyin" ad6327a8e166 dbyin/testrep

Bytes

Delete an image

# Docker RMI dbyin/sshd

Untagged: dbyin/sshd: Latest

Deleted: 3e6ddcc38145770486dbd2fcb5b3a6734fea447ab024c540e83d34acc8113a11

Deleted: Deleted

Deleted: 4ffa765d3fafa308edba9de3e59582451d6658e4c50cf9dda-bc18bfe410d2e9

Deleted: 95cc1fd701f6961585196a0b43e06404aa81f4ec65278d2249ad0716a2cf3d87

Deleted: Deleted

 

References

[1] https://docs.docker.com/installation/centos/

[2] working with docker Images

 

Deploy SSH Through docker

# Cat dockerfile

From centos

Maintainer dbyin

Run Yum install-y openssh-Server

Run echo "root: Root" | chpasswd

Expose 22

CMD ["/usr/sbin/sshd", "-d"]

 

 

Build Image

# Docker build -- Rm-T dbyin/sshd.

Sending build context to docker daemon 74.75 KB

Sending build context to docker daemon

Step 0: From centos

---> 1a7dc42f78ba

Step 1: maintainer dbyin

---> Running in f40dd8c16027

---> Ae21b4f05d98

Removing intermediate container f40dd8c16027

Step 2: Run Yum install-y openssh-Server

---> Running in a298b82f5fc1

Loaded plugins: fastestmirror

Determining fastest mirrors

* Base: mirrors.cug.edu.cn

* Extras: mirrors.cug.edu.cn

* Updates: mirrors.cug.edu.cn

Resolving Dependencies

--> Running transaction check

---> Package openssh-server.x86_64 0: 6. 4p1-8.el7 will be installed

--> Processing dependency: OpenSSH = 6.4p1-8. el7 for package: openssh-server-6.4p1-8.el7.x86_64

--> Running transaction check

---> Package OpenSSH. x86_64 0: 6. 4p1-8.el7 will be installed

--> Finished dependency resolution

 

Dependencies resolved

 

========================================================== ==========================================================

Package arch version repository size

========================================================== ==========================================================

Installing:

Openssh-server x86_64 6.4p1-8. el7 base 367 K

Installing for dependencies:

OpenSSH x86_64 6.4p1-8. el7 base 341 K

 

Transaction Summary

========================================================== ==========================================================

Install 1 package (+ 1 dependent package)

 

Total download size: 708 K

Installed size: 1.8 m

Downloading packages:

Warning:/var/Cache/Yum/x86_64/7/base/packages/openssh-server-6.4p1-8.el7.x86_64.rpm: Header V3 RSA/sha256 signature, key ID f4a80eb5: nokey

Public Key for openssh-server-6.4p1-8.el7.x86_64.rpm Is Not Installed

--------------------------------------------------------------------------------

Total 195 KB/S | 708 KB

Retrieving key from file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-7

Importing GPG key 0xf4a80eb5:

Userid: "CentOS-7 key (centos 7 official signing key) <[email protected]>"

Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5

Package: centos-release-7-0.1406.el7.centos.2.3.x86_64 (@ centos/$ releasever)

From:/etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-7

Running transaction check

Running transaction Test

Transaction test succeeded

Running transaction

Installing: openssh-6.4p1-8.el7.x86_64 1/2

Installing: openssh-server-6.4p1-8.el7.x86_64 2/2

Verifying: openssh-server-6.4p1-8.el7.x86_64 1/2

Verifying: openssh-6.4p1-8.el7.x86_64 2/2

 

Installed:

Openssh-server.x86_64 0: 6. 4p1-8.el7

 

Dependency installed:

OpenSSH. x86_64 0: 6. 4p1-8.el7

 

Complete!

---> 95cc1fd701f6

Removing intermediate container a298b82f5fc1

Step 3: Run echo "root: Root" | chpasswd

---> Running in 0aad665d3d2a

---> 4ffa765d3faf

Removing intermediate container 0aad665d3d2a

Step 4: Expose 22

---> Running in f3e0c11abc3f

---> Ab8ed0aaabab

Removing intermediate container f3e0c11abc3f

Step 5: cmd ["/usr/sbin/sshd", "-d"]

---> Running in 41d15fb205ff

---> 3e6ddcc38145

Removing intermediate container 41d15fb205ff

Successfully built 3e6ddcc38145

 

Start Image

# Docker run-D-p -- name test_sshd dbyin/sshd

Bytes

Container 22 is mapped to port 49153 of the host.

 

Stop container

# Docker stop test_sshd

Delete container

# Docker RM test_sshd

 

Error 1

Error: cannot start container restart: Port has already been allocated

Restart the docker service, see https://github.com/dotcloud/docker/issues/6476

 

Error 2

# SSH [email protected]-P 49153-V

Openssh_5.3p1, OpenSSL 1.0.1e-FIPS 11 Feb 2013

Debug1: Reading configuration data/etc/ssh/ssh_config

Debug1: Applying options *

Debug1: connecting to 172.16.213.129 [172.16.213.129] Port 49153.

Debug1: Connection established.

Debug1: permanently_set_uid: 0/0

Debug1: Identity file/root/. Ssh/identity type-1

Debug1: Identity file/root/. Ssh/identity-Cert Type-1

Debug1: Identity file/root/. Ssh/id_rsa type-1

Debug1: Identity file/root/. Ssh/id_rsa-cert-type-1

Debug1: Identity file/root/. Ssh/id_dsa type-1

Debug1: Identity file/root/. Ssh/id_dsa-cert-type-1

Debug1: Remote Protocol Version 2.0, remote software version openssh_6.4

Debug1: Match: openssh_6.4 Pat OpenSSH *

Debug1: enabling compatibility mode for protocol 2.0

Debug1: local version string SSH-2.0-OpenSSH_5.3

Debug1: ssh2_msg_kexinit sent

Read from socket failed: Connection reset by peer

 

Add the following content to rebuild the image

Run ssh-keygen-t rsa-F/etc/ssh/ssh_host_rsa_key

Run ssh-keygen-t dsa-F/etc/ssh/ssh_host_dsa_key

 

Then

...

Debug1: Exit status 254

Add the following content to rebuild the image. Refer to here

Run sed-Ri's/usepam Yes/# usepam Yes/G'/etc/ssh/sshd_config

Run sed-Ri's/# usepam no/G'/etc/ssh/sshd_config

 

Access

# SSH [email protected]-P 49153

 

References

[1] dockerizing an SSH daemon service

[2] docker: Using Linux containers to support portable Application Deployment


YY brother
Source: http://www.cnblogs.com/hustcat/
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

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.