Configure centos container to support ssh in Docker

In the beginning of Docker, the ubuntu system image has been downloaded, and a simple system command was successfully executed after starting the container

At this time, the container is closed. Next, we will establish a communication bridge with the container-configure SSH service

Here use centos mirroring for configuration

step

(1) Download the centos base image

(2) Write an integrated configuration file to support ssh on top of the basic image

(3) Run the configuration file and create a new image that supports ssh

(4) Run the container and start the ssh service at the same time

(5) Test, connect to the container with the ssh command

operating

(1) Download the centos base image

Execute download mirror command

# docker pull centos

(2) Write configuration files

Create a new test directory and create a new configuration file under it

# vi Dockerfile

content:

FROM        centos
MAINTAINER  dys "[email protected]"
RUN         yum install -y openssh openssh-server openssh-clients
RUN         mkdir -p /var/run/sshd
RUN         ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN         ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN         /bin/echo 'root:aaaaaa'|chpasswd
RUN         useradd dys
RUN         /bin/echo 'dys:aaaaaa'|chpasswd
RUN         /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g'/etc/pam.d/sshd
RUN         /bin/echo -e "LANG=\"en_US.UTF-8\"">/etc/default/local
EXPOSE      22
CMD         /usr/sbin/sshd -D

(3) Run the configuration file and create a mirror

Execute in the directory where the Dockerfile file is located:

docker build -rm -t dys/centos:ssh .

When the execution is complete, use the docker images command to see the mirror dys/centos just created

(4) Run the container

Execute the command to start the container

docker run -d -p 22 dys/centos:ssh

Use the docker ps command to check whether the startup is successful

If you see the name of the image you just created, it means that the container has run successfully

0.0.0.0:1035- >22 /tcp indicates that port 22 corresponds to port 1035, we can use the ssh client to connect

(5) Connection test

Use ssh command to connect to the container

User: dys is added to the above configuration file, and password: aaaaaa

ssh [email protected] -p 1035

Enter the password aaaaaa

Enter the container's command line

The most important thing in this process is the preparation of the Dockerfile configuration file, which will be described in detail later

Recommended Posts

Configure centos container to support ssh in Docker
CentOS container installation in Docker uses MySQL
Deploy Docker and configure Nginx in CentOS
Update gcc to 6.4.0 in centos
How to configure NTP to join the NTP pool project in CentOS
How to support TL-WDN7200H wireless USB network card in CentOS8?
Detailed steps to install and configure k8s cluster in centos 7
How to install PHP7.4 in CentOS
Install MySql with Docker in CentOS7
Install and configure Docker in Ubuntu
Container study notes CentOS7 install Docker
How to install HDP2.6 in Centos7.2
Install Centos7 operating system in Docker
Install and configure FreeIPA in Centos7
How to install Android SDK in centos7
Use supermin to make CentOS Docker image
Install CentOS7 virtual machine, configure docker suite
Install Docker CE in yum under CentOS 7
How to install and configure Elasticsearch on CentOS 7
How to install and use Docker on CentOS 7
How to set up SSH keys on CentOS 8
How to install and configure VNC on CentOS 8
Configure Nginx to start automatically based on CentOS 7
How to install and configure Redis on CentOS 8
How to configure /var/log/messages in Ubuntu system log
How to install and configure phpMyAdmin on CentOS 6
How to install php7.3 in centos8 custom directory
How to install and configure Owncloud on CentOS 8
Use command to clear specific hostname in CentOS7
How to install Docker CE on RHEL 8 / CentOS 8
How to install and configure Redmine on CentOS 8
Linux-ubuntu configure ssh
CentOS 7 install Docker
CentOS7 install Docker
Docker installation (CentOS7 installation)
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
Centos7 configure JDK
CentOS 6 install Docker
Centos8 install Docker
How to create a CentOS virtual machine in VMware
How to configure FTP server with Vsftpd on CentOS 8
Install PHP in yum under CentOS, configure php-fpm service
How to install and configure NFS server on CentOS 8
How to create a CentOS virtual machine in VMware
Complete steps to configure IP address in Ubuntu 18.04 LTS
How to quickly install docker on Linux (Centos version)
How to configure FTP server with Vsftpd on CentOS 8