Docker创建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 的详细介绍请点这里
Docker 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2016-11/137664.htm
今日推荐