In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to build php7 through custom images in docker. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Start with a simple docker installation.
To customize the image, we need to select a basic image to build our own image: to put it bluntly, in a container with a basic definition, execute the command to install various programs to generate the so-called Dockerfile file. In this case, the first step is to find a local image as the basic image to operate:
one
As shown in the figure above, let's build a Dockerfile based on centos
2 in the second step, we need to build a directory to store Dockerfile files
Build the docker_demo directory under root, store the Dockerfile files and the program files that need to be installed, because I want to build a custom environment for PHP, so let's get a PHP7 package.
Wget http://am1.php.net/get/php-7.0.0.tar.gz/from/this/mirror
And then change the name.
Now that PHP nginx is available, COMPOSER can operate on its own after the php is installed successfully.
The next step is to write the Dockerfile file, and before you do that, take a brief look at the keyword format written by Dockerfile:
FROM represents which image to base on.
Use of RUN installation software
Creator of MAINTAINER Mirror
The command that is executed when the CMD container starts, but there can be only one CMD command in a Dockerfile, and only the last CMD can be executed by more than one
The command that is executed when the ENTRYPOINT container starts, but there can be only one CMD command in a Dockerfile, and only the last one is executed by more than one
Which user does USER use to run container
The port exposed by the internal service of the EXPOSE container needs to be mapped on the run container on the CVM:
Docker run-d-p 8080 centos6xxx
The above command indicates that port 8080 inside the container is mapped to port 80 of the host.
ENV is used to set environment variables
ADD copies the files on the host to the corresponding path in container. The permissions of all files and folders copied to the container are 0755 and gid is 0. If the file is in a recognizable compression format, docker will help unzip it. ADD will only run once when build is mirrored, and will not be reloaded when container is run later.
Examples are:
ADD nginx-1.12.2.tar.gz / usr/local/src
VOLUME can hang local folders or folders from other containers into the container.
WORKDIR is used to switch directories (equivalent to cd directories)
The command specified by ONBUILD is not executed when the mirror is built, but in its child mirror.
After learning the basic Dockerfile commands, let's try to create this environment.
Docker pull centos
First download a basic image. If there is such a step, please ignore it. Here is my Dockerfile.
# base image# basic image FROM docker.io/centos# MAINTAINER writer MAINTAINER xy61521@163.com# put nginx-1.12.2.tar.gz into / usr/local/src and unpack nginx come on, nginx and PHP are put in the / usr/local/src directory of the basic image ahead of time Easy to compile and install ADD nginx-1.12.2.tar.gz / usr/local/srcADD php-7.0.0.tar.gz / usr/local/src# running required command install Nginx a series of messy dependency packages RUN yum install-y gcc gcc-c++ glibc make autoconf openssl openssl-develRUN yum install-y libxslt-devel-y gd gd-devel GeoIP GeoIP-devel pcre pcre-develRUN useradd-M-s / sbin/nologin nginx# change dir to / usr/local/src/nginx- 1.12.2WORKDIR / usr/local/src/nginx-1.12.2# execute command to compile nginxRUN. / configure-- user=nginx-- group=nginx-- prefix=/usr/local/nginx-- with-file-aio-- with-http_ssl_module-with-http_realip_module-- with-http_addition_module-- with-http_xslt_module-- with-http_image_filter_module-- with-http_geoip_module-- with-http_sub_module-- with-http _ dav_module-- with-http_flv_module-- with-http_mp4_module-- with-http_gunzip_module-- with-http_gzip_static_module-- with-http_auth_request_module-- with-http_random_index_module-- with-http_secure_link_module-- with-http_degradation_module-- with-http_stub_status_module & & make & & make install# install a local MysqlRUN yum install-y wgetRUN wget http://repo first .mysql.com / mysql57-community-release-el7-8.noarch.rpmRUN rpm-ivh mysql57-community-release-el7-8.noarch.rpmRUN yum install-y mysql-server# ends here Start installing php, cosmic convention Start installing some compiled dependent packages RUN yum-y install epel-releaseRUN yum-y install libmcrypt-develRUN yum-y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-develWORKDIR / usr/local/src/php-7.0.0# compile and install RUN. / configure-- prefix=/usr/local/php7-- with-config-file-path=/usr/local/php7/etc-- with-config-file-scan-dir=/usr/local/php7/etc / php.d-- with-mcrypt=/usr/include-- enable-mysqlnd-- with-mysqli-- with-pdo-mysql-- enable-fpm-- with-fpm-group=nginx-- with-gd-- with-iconv-- with-zlib-- enable-xml-- enable-shmop-- enable-sysvsem-- enable-inline-optimization-- enable-mbregex-enable-mbstring-enable-ftp-- enable-gd-native-ttf-- with-openssl-- enable-pcntl -enable-sockets-- with-xmlrpc-- enable-zip-- enable-soap-- without-pear-- with-gettext-- enable-session-- with-curl-- with-jpeg-dir-- with-freetype-dir-- enable-opcache & & make & & make installRUN cp php.ini-production / usr/local/php7/etc/php.ini
After the Dockerfile file is successfully built, docker build builds it
Docker build-t centos_lnmp:v1.
At the back. Represents the relative path to the current directory, or you can use an absolute path
And then there's a long wait.
Until the image is successfully built, we start all over again.
Docker images
We see that the image has been successfully built (there is a slight chance that the build will fail, if it fails, just delete the container and rebuild the image), and then run
Docker run-dt-p 80:80 centos_lnmp:v1
This is how the editor shares how to build php7 through custom images in docker. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are 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: 286
*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.