docker ubuntu apt-get php,Docker创建Ubuntu的LNMP镜像

本文详细介绍了如何在Ubuntu 16.04镜像上安装和配置LNMP(Linux, Nginx, MySQL, PHP7.0-FPM)环境,然后创建一个新的Docker镜像。步骤包括更新系统,安装所需软件,配置Nginx以支持PHP,启动服务,保存镜像,并最终发布到线上。此外,还提供了Docker相关教程链接。
摘要由CSDN通过智能技术生成

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

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 的详细介绍:请点这里

Docker 的下载地址:请点这里

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值