Docker最佳实践-部署LNMP环境

标签(linux): docker

笔者Q:972581034 交流群:605799367。有任何疑问可与笔者或加群交流

Docker最佳实践-部署LNMP环境

环境准备

[root@docker ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@docker ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 209M 517M 8.9M 1.1G 1.3G
Swap: 1.0G 0B 1.0G
[root@docker ~]# hostname -I
10.0.0.250 172.16.1.250
systemctl disable firewalld.service
systemctl stop firewalld.service
iptables -F

安装yum-utils,它提供yum-config-manager实用程序

yum install -y yum-utils

添加稳定版本库

yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

更新yum包索引

yum makecache fast

安装Docker社区版

yum install docker-ce -y

启动docker守护进程

systemctl enable docker
systemctl start docker
systemctl status docker

测试,,,网络延时问题可能会导致测试不成功,多测两次

docker run hello-world

查看镜像

c7是下面要用来启动容器的镜像,在centos镜像的基础上安装了常用软件包。

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
c7 latest 8af948261786 2 days ago 476 MB
centos latest a8493f5f50ff 6 weeks ago 192 MB

这里需要一些相关的软件包和配置文件,这里给大家提供了链接:http://pan.baidu.com/s/1eR8vdXg 密码:l1sj

创建web01

docker run --network=host -itd  --name=web01 -h web01 c7
docker attach web01

使用提供的软件包安装nginx

#nginx
yum localinstall -y nginx-1.10.2-1.x86_64.rpm

nginx配置文件

cd /application/nginx/conf/

[root@web01 conf]# cat nginx.conf
worker_processes  1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/blog.conf;
}
[root@web01 conf]# mkdir extra
[root@web01 extra]# ls
blog.conf

上传wordpress到站点根目录

[root@web01 extra]# cd /application/nginx/html/
[root@web01 html]# wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz
[root@web01 html]# tar xf wordpress-4.7.4-zh_CN.tar.gz
[root@web01 html]# chown -R www.www /application/nginx/html

启动nginx,安装php并启动

/application/nginx/sbin/nginx
chmod +x /etc/rc.local
echo "/application/nginx/sbin/nginx" >> /etc/rc.local #php
yum localinstall libiconv-devel-1.15-1.x86_64.rpm php-5.5.32-1.x86_64.rpm -y
/application/php/sbin/php-fpm
chmod +x /etc/rc.local
echo "/application/php/sbin/php-fpm" >> /etc/rc.local

创建数据库容器

docker run --network=host -itd  --name=db01 -h db01 c7
docker attach db01

安装并启动数据库

yum -y install mariadb mariadb-server
mysql_install_db --user=mysql
mysqld_safe &>/dev/null &
/usr/bin/mysqladmin -u root password '123456'
mysql -uroot -p123456

创建wordpress库和授权帐户

create database wordpress;
grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
grant all on wordpress.* to wordpress@'172.16.1.250' identified by '123456';

登录浏览器测试

来个美女养养眼

Docker最佳实践-部署LNMP环境

docker常用命令

http://www.cnblogs.com/Csir/p/6888474.html

上一篇:卡片标签


下一篇:RVCT的Linux环境变量配置 ARM® RVDS™ 4.1(b713)