Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create Docker image of supervisord-based sshd and other services under CentOS

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to create Docker image of supervisord-based sshd and other services under CentOS. I hope you will get something after reading this article. Let's discuss it together.

1. Sshd and httpd based on supervisord

Get the latest centos image

# docker pull centos:latest

Write Dockerfile (support apache+ssh services)

# mkdir / home/Dockerfile/webserver# cd / home/Dockerfile/webserver# vim Dockerfile

The Dockerfile content is as follows:

# This is a base commentFROM centos:latestMAINTAINER renguijiayi#yum install PackageRUN yum-y install net-toolsRUN yum-y install iputils iproute man vim-minimal openssh-server openssh-clientsRUN yum-y install httpdRUN yum-y install python-setuptoolsRUN easy_install supervisor#set sshdRUN ssh-keygen-Q-N ""-t dsa-f / etc/ssh/ssh_host_dsa_keyRUN ssh-keygen-Q-N ""-t rsa-f / etc/ssh/ssh_host_rsa_keyRUN ssh-keygen-t ecdsa-f / etc / ssh/ssh_host_ecdsa_key-N "" RUN sed-ri 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' / etc/pam.d/sshdRUN mkdir-p / root/.ssh & & chown root.root / root & & chmod 700 / root/.sshRUN echo' root:qwe123' | chpasswd#set supervisorRUN mkdir-p / var/log/supervisorADD supervisord.conf / etc/supervisord.conf#set portEXPOSE 22EXPOSE 80#set ENVENV LANG en_ | US.UTF-8ENV LC_ALL en_US.UTF-8#run supervisorCMD ["/ usr/bin/supervisord-c / etc/supervisord.conf"]

Maintain the service processes in the Docker container through supervisord, and write supervisord.conf:

# vi compilord.confession] nodaemon= truth [program: sshd] command=/usr/sbin/sshd-D [program: httpd] command=/usr/sbin/httpd-DFOREGROUND

Create a mirror and run:

# docker build-t test/webserver:v1 .2. Sshd and mysql based on supervisord

Go directly to Dockerfile:

FROM centos:centos6 MAINTAINER renguijiayi RUN rpm-ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmRUN yum install-y openssh-server sudo mysql-server mysql supervisorRUN sed-I 's/UsePAM yes/UsePAM no/g' / etc/ssh/sshd_config RUN useradd adminRUN echo "admin:admin" | chpasswdRUN echo "admin ALL= (ALL) ALL" > > / etc/sudoers RUN ssh-keygen-t dsa-f / etc/ssh/ Ssh_host_dsa_keyRUN ssh-keygen-t rsa-f / etc/ssh/ssh_host_rsa_keyRUN mkdir / var/run/sshd RUN / etc/init.d/mysqld start & &\ mysql-e "grant all privileges on *. * to 'root'@'%' identified by' letmein' "& &\ mysql-e" grant all privileges on *. * to 'root'@'localhost' identified by' letmein'; "& &\ mysql-u root-pletmein-e" show databases; "RUN mkdir-p / var/log/supervisorCOPY supervisord.conf / etc/supervisord.conf EXPOSE 22 3306CMD [" / usr/bin/supervisord "]

Create a supervisord.conf file in the same directory as Dockerfile, as follows:

[supervisord] nodaemon=true [program:sshd] command=/usr/sbin/sshd-D [program:mysqld] command=/usr/bin/mysqld_safe

Run the build command under the directory where Dockerfile is located to generate the image file, where mysql_server is used as the image file name:

Sudo docker build-t myserver.

Start the container first using the following command:

Sudo docker run-name=myserver-d-P myserver

After starting the container, you can use "sudo docker ps" to view it. At this point, you can see that the PORTS column is "0.0.0.0 22/tcp 49172-> 3306/tcp". Ports 22 and 3306 of the container will be mapped to ports 49171 and 49172 of the host machine.

You can access the ssh and mysql services with the following command:

Ssh admin@-p mysql-h-u root-pletmein-P 49172

You can also use "sudo docker inspect myserver | grep IPAddress" to view the container IP address, and then access the ssh and mysql services with the following command:

After reading this article, ssh admin@ mysql-h-u root-pletmein, I believe you have a certain understanding of "how to create Docker image for supervisord-based sshd and other services under CentOS". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 217

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report