Docker creates a CentOS image that supports SSH services

Source: Internet
Author: User
Tags docker ps docker run

To remotely connect Docker containers using the SSH service based on CentOS

Environment: Host CENTOS7, directly search Docker's CentOS image, download the latest version

1, first according to Docker:yum Install-y Epel-release

Yum Install-y Docker

2, start the Docker:systemctl start Docker.service

3. Use PS to see if Docker is started

PS aux |grep Docker

4. Download the Docker image of CentOS

Docker pull CentOS Download latest version

View image

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/18/wKioL1eFsYKwjorRAAAxzTwwG_Y557.png-wh_500x0-wm_3 -wmp_4-s_2786965160.png "title=" 1.png "alt=" Wkiol1efsykwjorraaaxztwwg_y557.png-wh_50 "/>

There are no other services or tools in the mirror, except for the underlying CentOS system

5. Start the CentOS container

Docker run-it--name=centos-ssh Centos/bin/bash

6. Enter into the container to upgrade and install the SSH component

Yum-y Update

Yum-y Install Openssh-server

7, edit the sshd configuration file/etc/ssh/sshd_config, the US person Pam parameter set to 0

8. Generate a key pair in the host, copy the generated public key file contents into the container's/root/.ssh/authorized_keys

If not, create.

ssh-keygen-t RSA Direct Carriage return, view public key contents, and copy into the container

Cat/root/.ssh/id_rsa.pub

9. Set the container root password

echo "root:123456" |chpasswd

10. Start the sshd service and exit the container

/usr/sbin/sshd-d

Exit

11. Generate a new CentOS image that supports SSH

First look at the container Docker ps-a

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/19/wKioL1eFwh2R1vW2AAAiJEAIQv4936.png-wh_500x0-wm_3 -wmp_4-s_2448724572.png "title=" 2.png "alt=" Wkiol1efwh2r1vw2aaaijeaiqv4936.png-wh_50 "/>

Generate image

Docker commit E813dfb36be9 Sshd-centos

A mirror named Sshd-centos is generated at this time

Docker Images View

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/84/1A/wKiom1eFwpLhW61IAAA5ArjgCBM470.png-wh_500x0-wm_3 -wmp_4-s_4154024350.png "title=" 3.png "alt=" Wkiom1efwplhw61iaaa5arjgcbm470.png-wh_50 "/>

12. Run the image and start the sshd service

Docker Run-p 10022:22-d sshd-centos/usr/sbin/sshd-d

Description: 10022 is the host's and container's communication port, outside the window (LAN) by accessing the address

SSH [email protected] Host IP 10022 (there is a space between the IP and the port, not:) will be able to enter the container



This article is from the "Tea Incense" blog, please be sure to keep this source http://chinawu.blog.51cto.com/10692884/1826004

Docker creates a centos image that supports SSH services

Related Article

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.