1.拉取centos鏡像
由于CentOS7在Docker上有一個DBUS(進程間通信機制)的BUG,所以這里建議下載CentOS6的鏡像。只需在鏡像名后面加上TAG既可
docker pull imagine10255/centos6-lnmp-php56
2.查看CentOS鏡像
docker images
3.創建CentOS容器
docker run -it -p 2222:22 -p 8888:80 -p 8080:8080 --name centos imagine10255/centos6-lnmp-php56
-p 2222:22 表示把容器中的22端口映射到主機的2222端口
-p 8888:80 表示把Nginx的端口80映射到主機的8888端口
-p 8080:8080 表示把Apache的端口8080(apach默認端口80,進入容器修改)映射到主機的8080
4.進入容器
docker exec -it centos bash
(說明:該容器中已經安裝msyql、apache、php,一下操作可以不執行)
5. 安裝MySQL
安裝鏈接https://blog.csdn.net/qq_38776582/article/details/90408708
6.安裝apache
yum install httpd
chkconfig httpd on // 設置開機啟動
修改apache端口
vim /etc/httpd/conf/httpd.conf
Listen 80 #這是Apache的默認監聽端口,修改你想要修改的端口就可以了
service httpd restart // 重啟apache服務
7.安裝php(進入容器安裝)
a.環境準備
yum install -y
gcc-c++ autoconf
libjpeg libjpeg-devel libpng
libpng-devel freetype freetype-devel
libpng libpng-devel libxml2 libxml2-devel
zlib zlib-devel glibc glibc-devel
glib2 glib2-devel bzip2 bzip2-devel
ncurses curl openssl-devel
gdbm-devel db4-devel libXpm-devel
libX11-devel gd-devel gmp-devel
readline-devel libxslt-devel
expat-devel xmlrpc-c xmlrpc-c-devel
libicu-devel libmcrypt-devel
libmemcached-devel
b.創建安裝目錄
mkdir -p /usr/local/php7.3
c.下載
cd /usr/local/php7.3
wget https://www.php.net/distributions/php-7.3.0.tar.gz
tar -zxvf php-7.3.0.tar.gz
d.配置
cd cd php-7.3.0
./configure --enable-fpm --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-apxs2=/usr/local/apache/bin/apxs --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
e:編譯
make && make install
d.其他處理
ln -s /usr/local/php7.3/bin/php /usr/local/bin/php
cp /usr/local/php7.3/etc/php-fpm.conf.default /usr/local/php7.3/etc/php-fpm.conf
cp /usr/local/php7.3/etc/php-fpm.d/www.conf.default /usr/local/php7.3/etc/php-fpm.d/www.conf
vim /usr/local/php7.3/etc/php-fpm.d/www.conf 將user和group設置成apache
cp php.ini-development /usr/local/php7.3/etc/php.ini
8. 保存配置好的鏡像
docker commit 容器ID centos-test
9.查看鏡像centos-test
docker images