Create CentOS Docker image with httpd service

  1. Pull the centos docker image with sshd service to the local
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
  1. Edit ssh, httpd startup script
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]
  1. Test httpd
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
  1. Mount [Host] (https://cloud.tencent.com/product/cdh?from=10680) project directory to the container httpd service directory
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

Create CentOS Docker image with httpd service
CentOS 7 install Docker service
Install MySql with Docker in CentOS7
Use supermin to make CentOS Docker image
CentOS 7 install Docker
CentOS7 install Docker
Docker installation (CentOS7 installation)
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
CentOS 6 install Docker
Centos8 install Docker
CentOS 6.8 create RAID-5
Install Docker on Centos7
CentOS 8 enable NTP service
CentOS 7 deploys RabbitMQ service
CentOS 7 deploy saltstack service
CentOS 8.0 installs docker error
CentOS 8-dnf install docker
CentOS7 deploys NFS service
Centos7 build DNS service
Centos6.8 deploy vnc service
install Docker on centos6.5
Docker CentOS installation method
CentOS 7 install Docker CE
Centos7 docker installation details