Docker container source code deployment httpd use storage volume to deploy the website (recommended)

Docker container source code deployment httpd use storage volume to deploy the website (recommended)

Deploy httpd with docker container source code and deploy website with storage volume

Create an httpd image

// Create an httpd container [root@localhost ~]# docker run -tid --name httpd centos
2d693e16f4f3734b127cbae90d189c1b4e78619a54ceec912a82d96cf4f1c345
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d693e16f4f3 centos "/bin/bash" 5 seconds ago Up 4 seconds httpd

// Connect to this container [root@localhost ~]# docker exec -it 2d693e16f4f3 /bin/bash
[root@2d693e16f4f3 /]# 

// Put the source package into the container [root@localhost ~]# docker cp /usr/src/apr-1.7.0.tar.gz 2d693e16f4f3:/usr/src/
[root@localhost ~]# docker cp /usr/src/apr-util-1.6.1.tar.gz 2d693e16f4f3:/usr/src/
[root@localhost ~]# docker cp /usr/src/httpd-2.4.49.tar.gz 2d693e16f4f3:/usr/src/
[root@2d693e16f4f3 /]# ls /usr/src/
apr-1.7.0.tar.gz debug kernels
apr-util-1.6.1.tar.gz httpd-2.4.49.tar.gz

// Install httpd from source code
[root@2d693e16f4f3 /]# useradd -r -M -s /sbin/nologin apache
[root@2d693e16f4f3 /]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
[root@2d693e16f4f3 /]# yum groups mark install 'Development Tools' -y
[root@2d693e16f4f3 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
[root@2d693e16f4f3 /]# cd /usr/src/
[root@2d693e16f4f3 src]# tar xf apr-1.7.0.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# tar xf apr-util-1.6.1.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# tar xf httpd-2.4.49.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# cd /usr/local/apr-1.7.0/
[root@2d693e16f4f3 apr-1.7.0]# vi configure
cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile" //Comment this line or delete it [root@2d693e16f4f3 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@2d693e16f4f3 apr-1.7.0]# make && make install
[root@2d693e16f4f3 local]# cd apr-util-1.6.1/
[root@2d693e16f4f3 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@2d693e16f4f3 apr-util-1.6.1]# make && make install
[root@2d693e16f4f3 apr-util-1.6.1]# cd ../httpd-2.4.49/ 
[root@2d693e16f4f3 httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
[root@2d693e16f4f3 httpd-2.4.49]# make && make install
[root@2d693e16f4f3 local]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@2d693e16f4f3 local]# source /etc/profile.d/httpd.sh
[root@2d693e16f4f3 local]# ln -s /usr/local/apache/include /usr/include/apache
[root@2d693e16f4f3 local]# apachectl start
[root@2d693e16f4f3 local]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process                                                      
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*    
[root@2d693e16f4f3 local]# cd /
[root@2d693e16f4f3 /]# 
[root@2d693e16f4f3 /]# 
[root@2d693e16f4f3 /]# vi start.sh
#!/bin/sh
/usr/local/apache/bin/apachectl start
/bin/bash
[root@2d693e16f4f3 /]# chmod +x start.sh


//Build image [root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","start.sh"]' 2d693e16f4f3 syblyw0806/httpd:v0.1
sha256:16913ce01fdceee9a389906cf385893120734b1a088b894cc5dce1a9ead252fd
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
syblyw0806/httpd v0.1 16913ce01fdc 6 seconds ago 713MB
busybox latest d23834f29b38 6 days ago 1.24MB
centos latest 5d0da3dc9764 2 months ago 231MB

Deploy nfs

You need to start a new virtual machine

[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# systemctl restart nfs-server.service
[root@localhost ~]# mkdir /nfs
[root@localhost ~]# chmod 777 /nfs/
[root@localhost ~]# vim /etc/exports
/nfs 192.168.200.136(rw)
[root@localhost ~]# systemctl restart nfs-server

Install nfs on the virtual machine with docker service

[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# showmount -e 192.168.200.137
Export list for 192.168.200.137:
/nfs 192.168.200.136

Mount

[root@localhost ~]# mount -t nfs 192.168.200.137:/nfs /var/www/html/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 883M 0 883M 0% /dev
tmpfs 901M 0 901M 0% /dev/shm
tmpfs 901M 8.9M 892M 1% /run
tmpfs 901M 0 901M 0% /sys/fs/cgroup
/dev/mapper/rhel-root 47G 23G 25G 48% /
/dev/nvme0n1p1 1014M 179M 836M 18% /boot
tmpfs 181M 0 181M 0% /run/user/0
overlay 47G 23G 25G 48% /var/lib/docker/overlay2/0a219b8bbb04290f6b1cc1ae29f5eb1a9bc713ff12c86c86c7e13d5c7ca63a0e/merged
192.168.200.137:/nfs 47G 2.2G 45G 5% /var/www/html

Create a container and map it

[root@localhost ~]# docker run -itd --name httpd1 -p 80:80 -v /var/www/html/:/usr/local/apache/htdocs 16913ce01fdc
42e38f1db61e49fafa0682125d0425e3d41c4f2db0f48e1973dee1905a90daf3
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
42e38f1db61e 16913ce01fdc "/bin/bash start.sh" 10 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp httpd1

Upload the code for the website we want to deploy

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
game.html images index.html js style

At this time, check nfs in a newly opened virtual machine

[root@localhost ~]# ls /nfs/
game.html images index.html js style

Access Test


This is the end of this article about deploying httpd in docker container source code and using storage volumes to deploy websites. For more information about deploying httpd in docker container, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Introduction to the steps of deploying redis in docker container
  • How to generate a docker image and complete container deployment in a spring boot project
  • Implementation of Docker Compose multi-container deployment

<<:  Summary of various forms of applying CSS styles in web pages

>>:  A brief discussion on HTML ordered lists, unordered lists and definition lists

Recommend

Solutions to Files/Folders That Cannot Be Deleted in Linux

Preface Recently our server was attacked by hacke...

How to use time as a judgment condition in MySQL

Background: During the development process, we of...

Implementation example of Nginx+Tomcat load balancing cluster

Table of contents introduction 1. Case Overview 2...

Handwriting implementation of new in JS

Table of contents 1 Introduction to the new opera...

Best Practices for Developing Amap Applications with Vue

Table of contents Preface Asynchronous loading Pa...

Detailed explanation of how to use awk in Linux

Before learning awk, we should have learned sed, ...

JavaScript pre-analysis, object details

Table of contents 1. Pre-analysis 1. Variable pre...

Briefly talk about mysql left join inner join

Preface I have been busy developing a cold chain ...

Detailed explanation of two quick ways to write console.log in vscode

(I) Method 1: Define it in advance directly in th...

Detailed examples of converting rows to columns and columns to rows in MySQL

mysql row to column, column to row The sentence i...

How to change MySQL character set utf8 to utf8mb4

For MySQL 5.5, if the character set is not set, t...

HTML end tag issue and w3c standard

According to the principles of W3C, each start tag...

How to connect to MySQL remotely through Navicat

Using Navicat directly to connect via IP will rep...

How to hide the version number and web page cache time in Nginx

Nginx optimization---hiding version number and we...