Docker custom SSH, Java and other basic service image

Source: Internet
Author: User

1. Launch a container based on the CentOS image

# docker Run–p 10022:22  -/]#

-P: Local port mapping container 22 port, is to test whether the normal login after SSH is started

2. Install Openssh-server, Java, etc. in the container

Yum Install -y-q openssh-server java-1.7.0-openjdk net-tools

3. Modify the Sshd_config configuration file

[Email protected]/]#Ssh-keygen-q-t Rsa-b2048-f/etc/SSH/ssh_host_rsa_key-n"'[[Email protected]/]#Ssh-keygen-q-t ecdsa-f/etc/SSH/ssh_host_ecdsa_key-n"'[[Email protected]/]#Ssh-keygen-T Dsa-f/etc/SSH/ssh_host_ed25519_key-n"'[[Email protected]/]#sed-I."s/useprivilegeseparation.*/useprivilegeseparation no/g"/etc/SSH/sshd_config [[email protected]/]#sed-I."S/usepam.*/usepam no/g"/etc/SSH/sshd_config

4. Change the root password

Echo ' Root:root ' |chpasswd

5. Start OpenSSH Service

 [[email protected]/]#/usr/sbin/sshd[[email protected] /]# Netstat-ntlpactive Internet connections (only servers) Proto Recv -Q send-q        Local address Foreign address State pid/program name TCP  0  0  0.0 . 0.0 : 22  0.0 . 0.0 :* LISTEN 1 /sshd tcp6  0  0 ::: 22  

6. Test whether the container can be landed

#SSH-P10022 192.168.62.200The authenticity of host'[192.168.62.200]:10022 ([192.168.62.200]:10022)'Can't be established.ECDSA key fingerprint is 7d:d5:8a:ea:5a: the: 9e:3d: the: Fe:DD: +: About: C2:d9:0e.are you sure your want to continue connecting (yes/no)?Yeswarning:permanently added'[192.168.62.200]:10022'(ECDSA) to the list of known hosts. [Email protected]192.168.62.200's Password:[Email protected] ~]#

7. Commit all operations just inside the container using commit

# Docker commit F743588bbeef docker-sshsha256 : 4d8d27a47d3fd2750cde8f5d0ead3af6f90dd972969a3dca369b52d1e6130085# Docker imagesrepository                          TAG                 IMAGE ID            CREATED             SIZEDocker-ssh                          latest              4d8d27a47d3f        7 seconds ago        192 MB

8. You can see a docker-ssh image in the mirror list

# docker run-d--name docker-SSH-P10022: Adocker-SSHd986e0bdc2b1072b39248a691ba73f6b297842373ca7a55457f3cd8d7fa5c435# DockerPS-acontainer ID IMAGE COMMAND CREATED STATUS PORTS namesd986e0bdc2b1 Docker-SSH                 "/usr/sbin/sshd-d"      3Seconds ago Up3Seconds0.0.0.0:10022- A/tcp docker-SSH# SSH-P10022 192.168.62.200The authenticity of host'[192.168.62.200]:10022 ([192.168.62.200]:10022)'Can't be established.ECDSA key fingerprint is 7d:d5:8a:ea:5a: the: 9e:3d: the: Fe:DD: +: About: C2:d9:0e.are you sure your want to continue connecting (yes/no)?Yeswarning:permanently added'[192.168.62.200]:10022'(ECDSA) to the list of known hosts. [Email protected]192.168.62.200's Password:[[Email Protected]d986e0bdc2b1 ~]#

Second, use Dockerfile to customize

mkdir Ssh-java # #创建一个空目录

CD Ssh-java && vim Dockerfile

From Centosmaintainer<email:[email protected] Blog:www.along.party>RUNYum Install-y-q Openssh-server java-1.7.0-openjdk net-Tools RUNSsh-keygen-q-t Rsa-b2048-f/etc/SSH/ssh_host_rsa_key-n"'RUNSsh-keygen-q-t ecdsa-f/etc/SSH/ssh_host_ecdsa_key-n"'RUNSsh-keygen-T Dsa-f/etc/SSH/ssh_host_ed25519_key-n"'RUNsed-I."s/useprivilegeseparation.*/useprivilegeseparation no/g"/etc/SSH/sshd_config RUNsed-I."S/usepam.*/usepam no/g"/etc/SSH/sshd_config RUNEcho 'Root:change'|chpasswd EXPOSE ACMD ["/usr/sbin/sshd","- D"]

from, RUN, EXPOSE, CMD, maintainer are dockerfile instructions , dockerfile instruction more detailed introduction

From: Specifies which base image is based on

Maintainer: Information for defenders

Run: Commands executed at the shell terminal

EXPOSE: Externally available ports

CMD: The start container is the command executed, each dockerfile can only have one cmd instruction, if there are more than one, then the last bar is executed.

Build image

ssh-java:1.7. 1  .

View a built image

Docker images| grep SSH-javassh-java                            1.7.  1               71fc498380f5         minutes ago      282 MB

Booting with mirroring

# DockerPS-acontainer ID IMAGE COMMAND CREATED STATUS PORTS names26b4dcc00246SSH-java:1.7.1                 "/usr/sbin/sshd-d"      3Seconds ago Up2Seconds0.0.0.0:32778- A/tcpSSH-java
#SSH-P32778 192.168.62.200The authenticity of host'[192.168.62.200]:32778 ([192.168.62.200]:32778)'Can't be established.ECDSA key fingerprint is 7d:d5:8a:ea:5a: the: 9e:3d: the: Fe:DD: +: About: C2:d9:0e.are you sure your want to continue connecting (yes/no)?Yeswarning:permanently added'[192.168.62.200]:32778'(ECDSA) to the list of known hosts. [Email protected]192.168.62.200's Password:[Email protected] ~]#

Docker custom SSH, Java and other basic service image

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.