手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Docker创建Ubuntu的LNMP镜像

[日期:2016-11-29] 来源:Linux社区  作者:turtleo [字体: ]

本文讲述的是如何在原有的Ubuntu镜像上搭建LNMP开发环境,并生成新的镜像。

一、下载ubuntu:16.04镜像

docker pull ubuntu:16.04

二、运行ubuntu镜像

docker run -i -t ubuntu:16.04 bash

三、在ubuntu镜像中搭建lnmp环境

更新ubuntu系统

apt-get update

安装php7.0

apt-get install  php

安装nginx

apt-get install nginx

安装MySQL

apt-get install mysql*

启动nginx、mysql、php7.0-fpm服务

service nginx start
service mysql start
service php7.0-fpm start

配置nginx

index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #      # With php7.0-cgi alone:
        #      fastcgi_pass 127.0.0.1:9000;
                # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

退出镜像

exit1

四、生成新的镜像

查看之前编辑的镜像id

docker ps -l

保存之前编辑的镜像到一个新镜像

docker commit -m "提交信息" --author "作者" 镜像id  新镜像名

五、运行新的镜像

docker run -d -p 80:80 -v /var/www/html:/var/www/html turtlell/lnmp:1.2 /sbin/init

其中 -d 是以daemon模式运行
 -p 80:80是将本地的80端口映射到容器的80端口
 -v /var/www/html:/var/www/html 是将本地的/var/www/html目录挂载到容器的/var/www/html目录上,可以在本地的/var/www/html中编写代码

进入新镜像,启动nginx、mysql、php7.0-fpm服务

docker ps

docker exec -it 进程id bash

访问localhost

五、将新的镜像发布到线上

docker login

docker pull 镜像名:版本号

更多Docker相关教程见以下内容: 

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm 

Ubuntu 14.04安装Docker  http://www.linuxidc.com/linux/2014-08/105656.htm 

Ubuntu使用VNC运行基于Docker的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm 

阿里云CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm 

Ubuntu 15.04下安装Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm 

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm 

在 Ubuntu 15.04 上如何安装Docker及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm 

Docker 的详细介绍请点这里
Docker 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-11/137664.htm

linux
相关资讯       LNMP  LNMP镜像 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款