您的当前位置:首页>全部文章>文章详情

使用 docker 搭建 ubuntu+nginx+php 容器

发表于:2020-04-07 11:50:37浏览:55次TAG: #docker

使用 docker 搭建 ubuntu+nginx+php 容器

搜索镜像

$ docker search ubuntu
NAME      DESCRIPTION                                     STARS         OFFICIAL      AUTOMATED
ubuntu    Ubuntu is a Debian-based Linux operating sys…   10699         [OK]

拉取镜像

$ docker pull ubuntu

运行容器

$ docker run --name ubuntu_nginx_php7 -p 80:80 -v /Users/yuchong/www:/home/www -it -d ubuntu /bin/bash -c "/etc/rc.local; /bin/bash"

# -p 本地端口:容器端口 -> 端口映射
#     - 5000:5000 -> 单个端口映射
#     - 9001-9020:9001-9020 -> 多个端口映射
#     - -p 5001:5001 -p 3306:3306 -> 多端口映射
# -v 本地目录:容器目录-> 挂载本地目录
#     - -v /a:/a -v /b:/b 多目录挂载
# -c 开机执行的命令
    - vim /etc/rc.local
        /etc/init.d/php7.2-fpm start
        /etc/init.d/nginx start
        exit 0
    - chmod +x /etc/rc.local

(注意) 这里的命令可以不用这么复杂,只需要配置好容器内部的环境,下面命令就够用了
$ docker run --name ubuntu_nginx_php7 -p 80:80 -i -t -d ubuntu /bin/bash

进入镜像

$ docker exec -it ubuntu_nginx_php7 /bin/bash

更新软件源

root@79330c214f01:/# apt-get update

安装 nginx

$ apt-get install nginx

启动 nginx

$ /etc/init.d/nginx start

# 另一种方式启动
$ /usr/sbin/nginx

安装 php

$ apt-get install php
$ apt-get install php-fpm

### 安装 php 扩展

修改 php 端口

$ vim /etc/php/7.2/fpm/pool.d/www.conf
# 修改
; listen = /run/php/php7.2-fpm.sock
listen = 127.0.0.1:9000

启动 php-frpm

$ /etc/init.d/php7.2-fpm start

# 另一种方式启动
 /usr/sbin/php-fpm7.2

提交镜像

$ docker commit -m "ubuntu_bozhong" -a "yuchong" 7a7e0a552c58 ubuntu_bozhong
# -m 提交时的说明文字
# -a 镜像作者
# -c 使用Dockerfile指令来创建镜像
# -p 在commit时,将容器暂停

$ docker images
栏目分类全部>
腾讯云采购季云服务器一折促销