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