Docker 镜像只制作LNMP + redis
一、制作背景
Window10 + VM11 + opensuse + docker + centos7dockers镜像
这里主要是分享LNMP + redis 镜像的制作,跳过其他。
二、配置LNMP
1、安装docker 镜像 centos7
Yum install docker-io 安装docker
Service docker start 启动 docker 服务
Chkconfig docker on 设置开机启动
Docker pull centos:7 从docker 仓库中获取镜像(这里的镜像)
可以通过 docker images 列出本地仓库中存在的docker 镜像
docker run -it -p 80:80 -p 10000:10000 --name=test2 centos:7
跑起镜像centos:7 开放80 和 10000端口权限 命名为 test2
Ctrl + p 、Ctrl + q 退出容器
Docker ps 查看正在运行的容器
Docker attach test2 进入正在运行的test2容器 ( L已经配好了)
2、安装 mysql
把所需要的源代码下载至 /usr/local/src
安装M mysql
Yum install –y wget
Wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz 获取mysql 源代码
将压缩包解压到/usr/local/mysql 中
命令如下:
cd /usr/local tar -zxvf /usr/local/src/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.28-linux-glibc2.5-x86_64 mysql
创建一个mysql 用户组和mysql用户并将 mysql目录的所有的权限给mysql
Groupadd mysql Useradd –r –g mysql mysql Cd /usr/local/mysql Chown –R mysql:mysql ./
执行命令 ./scripts/mysql_install_db --user=mysql 安装mysql
安装之前先检查 有没有安装 perl 如果没有先安装:yum –y install perl perl-devel perl-Module-Install.noarch
再检查有没有安装libaio ,如果没有就安装:yum –y install libaio libaio-devel
安装完提示:
To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h 59ee867f63a2 password 'new-password' Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file ./my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as ./my-new.cnf, please compare it with your file and take the changes you need.
修改当前目录拥有者为root用户:执行命令 chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令 chown -R mysql:mysql data
support-files/mysql.server start(假如启动成功)
./bin/mysqladmin -u root password '密码'
检查是否安装成功: /usr/local/mysql/bin/mysql –u root –p
然后输入密码
3、安装 N nginx
wget http://nginx.org/download/nginx-1.9.8.tar.gz
1:首先安装Nginx所需要的库
a.GCC编译器
yum install -y gcc
b.G++编译器:C++来编译Nginx的http模块
yum install -y gcc-c++
c.PCRE库:正则表达式
yum install -y pcre pcre-devel
d.zlib库
对HTTP包的内容作gzip压缩
yum install -y zlib zlib-devel
e.OpenSSL开发库
如果服务器要支持在SSL协议上传输HTTP就需要OpenSSL
yum install -y openssl openssl-devel
tar –zxvf nginx-1.9.8.tar.gz
wget http://nginx.org/download/nginx-1.9.8.tar.gz
mkdir /usr/local/nginx
1:首先安装Nginx所需要的库
a.GCC编译器
yum install -y gcc
b.G++编译器:C++来编译Nginx的http模块
yum install -y gcc-c++
c.PCRE库:正则表达式
yum install -y pcre pcre-devel
d.zlib库
对HTTP包的内容作gzip压缩
yum install -y zlib zlib-devel
e.OpenSSL开发库
如果服务器要支持在SSL协议上传输HTTP就需要OpenSSL
yum install -y openssl openssl-devel
./configure --prefix=/usr/local/nginx
make && make install
4、安装P
wget yum -y install make cmake automake autoconf kernel-devel ncurses-devel libxml2-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel openldap openldap-devellibxslt-devel libldap libldap-devel ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-zlib --with-curl --with-curlwrappers --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-openssl --enable-sockets --enable-zip --without-pear
跑起fpm
命令:/usr/local/php/sbin/php-fpm
编辑 nginx.conf如下:
新建index.php和connectMysql.php两个文件 ,保存在/usr/local/nginx/html
Index.php
内容:<?php phpinfo(); ?>
connectMysql.php
内容:
用浏览器跑他们两个
127.0.0.1/index.php
127.0.0.1/connectMysql.php
5、安装redis
wget http://download.redis.io/releases/redis-2.8.3.tar.gz
tar –zxvf redis-2.8.3.tar.gz
cd redis-2.8.3
make
cd src
mkdir /usr/local/redis
cp redis-server /usr/local/redis cp redis-benchmark /usr/local/redis cp redis-cli /usr/local/redis cp ../redis.conf /usr/local/redis
cd /usr/local/redis
跑起redis redis-server redis.conf
6、编译 phpreids
下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
cd /usr/local/src #进入软件包存放目录
wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
tar -zxvf 2.2.4.tar.gz #解压
cd phpredis-2.2.4 #进入安装目录
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure --with-php-config=/usr/local/php/bin/php-config #配置
make #编译
make install #安装
安装完成之后,出现下面的安装路径
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
vi /usr/local/php/etc/php.ini #编辑配置文件,在最后一行添加以下内容
添加
extension="redis.so"
:wq! #保存退出
sudo service nginx restart
sudo /etc/init.d/php-fpm restart
浏览器访问:127.0.0.1/index.php 查看redis 扩展是否已经装上
退出容器 exit
要先登陆才能上传哦
docker commit -m "create my first php env" -a "sw_cyz" 59ee867f63a2 cover/phpenv:v1
docker push cover/phpenv:v1