In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to make LAMP by Dockerfile. It is very detailed and has certain reference value. Friends who are interested must finish it.
Dockerfile makes LAMP (mysql default password is empty)
Environment:
Httpd 2.4.37
Mysql 5.6.40
Php 7.0.27
[root@oracle ~] # service docker start
Create docker Volum
[root@oracle ~] # docker volume create lamp_www
[root@oracle ~] # docker volume create lamp_apache_conf
[root@oracle ~] # docker volume create lamp_mysql_conf
[root@oracle ~] # docker volume create lamp_mysql_data
Create a / var/lib/docker/volumes directory on the host
[root@oracle ~] # mkdir / var/lib/docker/volumes (this path is docker by default and cannot be modified.)
[root@oracle ~] # mkdir / root/lamp
[root@oracle ~] # cd / root/lamp
[root@oracle my_mysql] # pwd
/ root/lamp
[root@oracle my_mysql] # vi Dockerfile
FROM centos
MAINTAINER norman "normanjin@163.com"
# APACHE
# install wget
RUN yum install-y wget
RUN yum install-y gcc make apr-devel apr apr-util apr-util-devel pcre-devel
RUN yum install-y net-tools
# download and decompress the source package. You can also download httpd-2.4.37.tar.gz to / root/lamp, and then directly use COPY httpd-2.4.37.tar.gz / usr/local/src (that is, transfer the httpd-2.4.37.tar.gz under the local directory directly to the / usr/local/src directory of image, and then execute WORKDIR / usr/local/src and RUN tar-zxvf httpd-2.4.37.tar.gz)
WORKDIR / usr/local/src
RUN wget http://apache.fayea.com/httpd/httpd-2.4.37.tar.gz
RUN tar-zxvf httpd-2.4.37.tar.gz
WORKDIR / usr/local/src/httpd-2.4.37
# compile and install apache (--enable-so so that you can use DSO. Modules that are missing in the compilation installation can be installed through the DSO installation method)
RUN. / configure-- enable-so
RUN make
RUN make install
# modify apache configuration file
RUN sed-I 's/#ServerName www.example.com:80/ServerName localhost:80/g' / usr/local/apache2/conf/httpd.conf
# set apache to boot automatically, and add a line / usr/local/apache2/bin/httpd at the end of / etc/rc.local (I don't know why apache just can't boot automatically)
RUN echo "/ usr/local/apache2/bin/httpd" > > / etc/rc.local
# Open port 80
EXPOSE 80
# MYSQL
ADD http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm / usr/local/
RUN rpm-ivh / usr/local/mysql-community-release-el7-5.noarch.rpm
RUN yum install mysql-server-y
EXPOSE 3306
CMD ["systemctl enable mysqld"]
CMD ["systemctl start mysqld"]
# PHP
RUN yum-y install libxml2 libxml2-devel bzip2 bzip2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel libcurl libcurl-devel
RUN yum install-y perl
WORKDIR / usr/local/src
RUN wget http://101.96.10.63/cn2.php.net/distributions/php-7.0.27.tar.gz
RUN tar-zxvf php-7.0.27.tar.gz
WORKDIR / usr/local/src/php-7.0.27
RUN sed-I's impulse impulse replace with path to explain the explanation to explain the use rbinand to usr/local/apache2/bin/apxs
RUN. / configure-prefix=/usr/local/php-with-config-file-path=/usr/local/php/etc-with-apxs2=/usr/local/apache2/bin/apxs-enable-mysqlnd-with-mysqli=mysqlnd-with-pdo-mysql=mysqlnd-with-mysql-sock=/var/lib/mysql/mysql.sock
RUN make
RUN make install
WORKDIR / usr/local/src/php-7.0.27
RUN cp php.ini-production / usr/local/php/etc/php.ini
# remove the comments on the following configuration statement ";"
RUN sed-I's extensionsextensionworthy phppages mysqli.dllextensionphphands mysqli.dllroomg' / usr/local/php/etc/php.ini
RUN sed-I's usr/local/php/etc/php.ini; extension_dir = "ext" # extension_dir = "ext" # g'/ usr/local/php/etc/php.ini
RUN echo "PATH=$PATH:/usr/local/php/bin" > > / root/.bashrc
RUN export PATH
# make the configuration effective immediately
RUN source / etc/profile
[root@oracle my_mysql] # docker build-t lamp. (Dockerfile creates a mirror)
Note: RUN sed-I's impulse impulse replaceqqt with path to explain usr/local/apache2/bin/apxs to explain to USR to bind to usr/local/apache2/bin/apxs
(- I: directly modify the contents of the read file instead of outputting it to the terminal) (the content between # # can be modified directly)
(modify the first line of / usr/local/apache2/bin/apxs file #! / replace/with/path/to/perl/interpreter-w to #! / usr/bin/perl-w)
If you do not make the above changes, the following errors will occur:
Sorry, I cannot run apxs. Possible reasons follow:
Perl is not installed
Apxs was not found. Try to pass the path using-with-apxs2=/path/to/apxs
Apache was not built using-enable-so (the apxs usage page is displayed)
Create container
[root@oracle my_mysql] # docker run-itd-- privileged=true-p 80:80-p 3306 itd 3306-v lamp_www:/usr/local/apache2/htdocs-v lamp_apache_conf:/usr/local/apache2/conf-v lamp_mysql_conf:/etc/mysql-v lamp_mysql_data:/var/lib/mysql-- name lamp lamp / usr/sbin/init
[root@oracle my_mysql] # docker exec-I-t lamp bash
Change the configuration file of apache to parse the php file
[root@62b35d09adba htdocs] # vi / usr/local/apache2/conf/httpd.conf
Add the following at the end of the LoadModule
LoadModule php7_module modules/libphp7.so
(compiling uses-- with-apxs2=/usr/local/apache2/bin/apxs,httpd.conf to have this module)
# # usually it will be added automatically after the PHP is compiled and installed correctly. If not, it needs to be added manually.
Next, check the php dynamic link library file generated in the apache directory and find the existence of the libphp7.so file in the directory / usr/local/apache2/modules. What if it doesn't exist? Then php is not installed correctly.
Then add the following in
AddType application/x-httpd-php .php
Since the boot auto-startup apache is not successfully set in image, start apache manually here
/ usr/local/apache2/bin/httpd
[root@62b35d09adba htdocs] # vi / usr/local/apache2/htdocs/info.php
The test opens http://192.168.1.203/info.php and sees the following instructions for successfully configuring PHP
Create database data
Root@9a44df59980e:/# mysql-uroot-p
Mysql > show databases
Mysql > create database example default charset=utf8
Mysql > show create database example\ G
Mysql > use example
Mysql > create table tbl (idx integer (3), UserName varchar (30), LastName varchar (50), FreeText varchar (100) ENGINE=InnoDB AUTO_INCREMENT=1 default charset=utf8
Mysql > show create table tbl\ G
Mysql > show columns from tbl
Mysql > select from tbl
Mysql > insert into tbl values (1) just a test')
Mysql > update tbl set UserName='Berber' where UserName='Rafi'
Mysql > select from tbl
Mysql > delete from tbl where idx=1 limit 1
Mysql > insert into tbl values (1) just a test')
Mysql > select * from tbl
Mysql > quit
Bye
When the database is created and viewed on the host machine, you can see the database example created in the container above.
[root@oracle _ data] # ls-la / var/lib/docker/volumes/lamp_mysql_data/_data
Total 110604
Drwxr-xr-x. 5 mysql mysql 147 Dec 4 16:08.
Drwxr-xr-x. 3 root root 19 Dec 4 16:03..
-rw-rw----. 1 mysql mysql 56 Dec 4 16:03 auto.cnf
Drwx-. 2 mysql mysql 50 Dec 4 16:08 example
-rw-rw----. 1 mysql mysql 12582912 Dec 4 16:08 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Dec 4 16:08 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Dec 4 16:03 ib_logfile1
Drwx-. 2 mysql mysql 4096 Dec 4 16:03 mysql
Srwxrwxrwx. 1 mysql mysql 0 Dec 4 16:03 mysql.sock
Drwx-. 2 mysql mysql 4096 Dec 4 16:03 performance_schema
Create a PHP file (one of the biggest changes compared to PHP5,PHP7 is the removal of the mysql extension. It is recommended to use mysqli or pdo_mysql. In fact, starting with PHP5.5, PHP begins to prepare to abandon the mysql extension. If you use the mysql extension, you may have seen the prompt "Deprecated: mysql_connect (): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in". So in future programs, in order to maintain compatibility, we should minimize the use of mysql extensions for database connections.)
(the following example uses mysqli_query instead of mysql_connect)
[root@2fec8154c8d0 php-7.0.27] # vi / usr/local/apache2/htdocs/index.php
Web Database Sample Index
Data from tbl
Test LAMP to open http://192.168.1.203/index.php, and you can already see the data
Push (push) Docker image to Docker Hub
# Log in to docker
[root@oracle ~] # docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: normanjin
Password:
WARNING! Your password will be stored unencrypted in / root/.docker/config.json.
Configure a credential helper to remove this warning. See
Https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@oracle lamp] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Lamp latest eefbed0e6b7b 17 minutes ago 1.78GB
Centos latest 75835a67d134 8 weeks ago 200MB
# push image through push command
[root@oracle ~] # docker push lamp
The push refers to repository [docker.io/library/lamp]
1b1c29220282: Preparing
Db96da7dd05d: Preparing
9afcea8cdf38: Preparing
C065e12e3ddc: Preparing
1edb6ba7364f: Preparing
9e9ddeffb3e1: Waiting
Fb4939b9199d: Waiting
69d3c2a86f3b: Waiting
2ae58cef8e6a: Waiting
Eae38119b1e1: Waiting
Fc07c703bbb0: Waiting
538504760e19: Waiting
F8fc7dea67ee: Waiting
17de3d8f6769: Waiting
919050766d2e: Waiting
Eed51e86558f: Waiting
Cda478af73dc: Waiting
0a5472ea842c: Waiting
222ef4196d28: Waiting
D907cbf78296: Waiting
C8d2020c16c8: Waiting
7ef65f464278: Waiting
852384e0fb85: Waiting
Da7d2b992ce3: Waiting
8f142509c0d9: Waiting
F972d139738d: Waiting
Denied: requested access to the resource is denied
[root@oracle ~] # docker tag lamp normanjin/lamp (add tag to lamp image)
[root@oracle lamp] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Lamp latest eefbed0e6b7b 28 minutes ago 1.78GB
Normanjin/lamp latest eefbed0e6b7b 28 minutes ago 1.78GB
Centos latest 75835a67d134 8 weeks ago 200MB
[root@oracle ~] # docker push normanjin/lamp
The push refers to repository [docker.io/normanjin/lamp]
1b1c29220282: Pushed
Db96da7dd05d: Pushed
9afcea8cdf38: Pushed
C065e12e3ddc: Pushed
1edb6ba7364f: Pushed
9e9ddeffb3e1: Pushed
Fb4939b9199d: Pushed
69d3c2a86f3b: Pushed
2ae58cef8e6a: Pushed
Eae38119b1e1: Pushed
Fc07c703bbb0: Pushed
538504760e19: Pushed
F8fc7dea67ee: Pushed
17de3d8f6769: Pushed
919050766d2e: Pushed
Eed51e86558f: Pushed
Cda478af73dc: Pushed
0a5472ea842c: Pushed
222ef4196d28: Pushed
D907cbf78296: Pushed
C8d2020c16c8: Pushed
7ef65f464278: Pushed
852384e0fb85: Pushed
Da7d2b992ce3: Pushed
8f142509c0d9: Pushed
F972d139738d: Pushed
Latest: digest: sha256:9567362dba14631b8fc7d1defd0e9eb5adca785e97d7410a9fc5d9d1483a3d17 size: 5790
# Note: the speed of pushing Docker Hub is very slow. Wait patiently and it is likely to fail. If you fail, you will try to retransmit it many times.
View the images I have posted on Docker Hub
Https://hub.docker.com/r/normanjin/lamp/, as shown in the following figure
Searching on Docker Hub can also be found.
At this point, I have published my image to the Docker Hub repository.
The above is all the content of the article "how Dockerfile makes LAMP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.