command:
docker pull freedoms1988/centos7-sshd
Explanation:
docker pull【pull command】 freedoms1988/centos7-sshd [remote mirror name]
Second, start the centos docker container with sshd service
command:
docker run -p 10022:22-d freedoms1988/centos7-sshd /usr/sbin/sshd -D
Explanation:
docker run【Run command】-p 10022:22 [Mapping port: host 10022 to docker22]-d freedoms1988/centos7-sshd [local mirror name]/usr/sbin/sshd -D【Start sshd command】
Three, log in to the container
command:
ssh root@localhost -p 10022
Explanation:
ssh root【User】@localhost【host name】-p 10022【Port number】
Fourth, install openssh-clients
command:
yum install openssh-clients
Explanation:
yum install [installation command] openssh-clients [software name]
Five, install wget
command:
yum install wget
Explanation:
yum install [installation command] wget [software name]
Six, download httpd
command:
1、 cd /usr/local/src
2、 wget [http://apache.01link.hk//httpd/httpd-2.4.29.tar.gz](http://apache.01link.hk//httpd/httpd-2.4.29.tar.gz)3、tar -zxvf httpd-2.4.29.tar.gz
4、 cd httpd-2.4.29
Explanation:
1、 Enter the source code temporary path
2、 Download httpd2.4.Chapter 293: Unzip
4、 Enter httpd2.4.29 source path
Seven, install gcc, make, apache dependencies
command:
yum install -y gcc make apr-devel apr apr-util apr-util-devel pcre-devel
Explanation:
yum install【installation command】-y【Automatically confirm parameters】 gcc make apr-devel apr apr-util apr-util-devel pcre-devel [software name]
Eight, compile and install httpd
command:
1、. /configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
2、 make && make install
Explanation:
1、 Configure compilation parameters, installation path
2、 Compile and install
Nine, modify httpd configuration
command:
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g'/usr/local/apache2/conf/httpd.conf
Explanation:
sed【Search command】-i【Replacement parameter】's/#ServerName www.example.com:80/ServerName localhost:80/g'【Parameter to be replaced/Replacement parameters/usr/local/apache2/conf/httpd.conf[file path]
Ten, start httpd
command:
1、 /usr/local/apache2/bin/httpd
2、 systemctl enable httpd.service
Explanation:
1、 Start httpd
2、 Set up auto start
operating:
1、 cd /usr/local/sbin
2、 vim httpd.sh
3、 Edit content:
#! /bin/bash
/usr/sbin/sshd &/usr/local/apache2/bin/httpd -D FOREGROUND
4、 Save and exit
5、 Change file permissions
chmod 755 httpd.sh
Twelve, generate centos mirror that supports ssh
command:
1、 docker ps -a
2、 docker commit 6c40d0d2d8e centos7-sshd
3、 docker images
Explanation:
1、 docker ps [list container list]-a [Optional parameter, list the list of unstarted containers]
2、 docker commit [submit] 6c40d0d2d8e [container id in the previous step] centos7-httpd2.4-sshd [custom image name]
3、 docker images [list local mirror list]
Thirteen, use the generated image to run the container
command:
docker run -d -p 10022:22-p 8080:80 freedoms1988/centos7-httpd2.4-sshd /usr/local/sbin/httpd.sh
Explanation:
docker run【Run command】-d【Background process parameters】-p 10022:22 [Port mapping: host 10022 to docker22]-p 8080:80 [Port mapping: host 8080 to docker80] freedoms1988/centos7-httpd2.4-sshd [mirror name]/usr/local/sbin/httpd.sh [Run script path when running mirror]
operating:
Enter localhost in the browser:8080
result:
See it'work
Fifteen, test sshd
operating:
ssh root@localhost -p 10022
result:
Successfully entered the container
command:
docker run -d -p 10022:22-p 8080:80-v /Users/freedoms/work/Docker/httpd/www:/usr/local/apache2/htdocs freedoms1988/centos7-httpd2.4-sshd /usr/local/sbin/httpd.sh
Explanation:
docker run【Run command】-d -p 10022:22 [Port mapping: host 10022 to docker22]-p 8080:80 [Port mapping: host 8080 to docker80]-v /Users/freedoms/work/Docker/httpd/www:/usr/local/apache2/htdocs [Directory mapping: host directory:docker directory] freedoms1988/centos7-httpd2.4-sshd [Mirror name]/usr/local/sbin/httpd.sh [Run script path when running mirror]
Seventeen, test the validity of the host project directory mount
operating:
1、 Create an index in the host project directory.html file and enter any content
2、 Curl localhost in the host or container:8080
result:
Should print index.html file content
Recommended Posts