docker创建ubuntu的lnmp镜像

本文讲述的是如何在原有的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;
}

退出镜像

exit

四、生成新的镜像

查看之前编辑的镜像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 镜像名:版本号
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值