安装docker参考 https://yeasy.gitbooks.io/docker_practice/content/install/ubuntu.html
拉取ubuntu16.04 作为基本镜像
```
docker pull ubuntu:16.04
```
建个空目录 ,创建Dockerfile
```
# vi Dockerfile
FROM ubuntu:16.04
RUN apt update && apt install -y \
nginx \
php \
php-mysql \
php-memcached \
php-msgpack \
php-mbstring \
php-dom \
php-zip \
php7.0-dev \
composer \
wget \
unzip \
re2c \
libgearman-dev \
# 删除apt缓存
&& rm -rf /var/lib/apt/lists/* \
# 删除nginx默认配置
&& rm -rf /etc/nginx/sites-enabled/default \
# 创建默认的日志目录
&& mkdir -p /opt/log \
&& chown www-data /opt/log -R
COPY be-report /etc/nginx/sites-enabled
RUN mkdir -p /tmp/install \
&& cd /tmp/install \
&& wget https://github.com/wcgallego/pecl-gearman/archive/master.zip \
&& unzip master.zip \
&& cd pecl-gearman-master \
&& phpize \
&& ./configure \
&& make install \
&& echo "extension=gearman.so" > /etc/php/7.0/mods-available/gearman.ini \
&& phpenmod -v ALL -s ALL gearman \
&& php -m | grep gearman
ENTRYPOINT service nginx start && service php7.0-fpm start && /bin/bash
EXPOSE 80
```
创建默认的nginx配置,文件名be-report
```
# vi be-report
server {
listen 80;
server_name _;
root /var/www/html/be-report/public/;
index index.php;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ ^(.+\.php)(.*)$ {
alias /var/www/html/be-report/public/;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 9999999999;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $DOCUMENT_ROOT$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT/$fastcgi_script_name;
include fastcgi_params;
}
location / {
rewrite ^(.*)$ /index.php/$1 last;
}
}
```
从Dockerfile创建镜像,镜像名为 be-report
```
docker build -t be-report .
```
从镜像运行容器
```
#/home/xj3hj2/docker/ 需根据代码位置调整
docker run -it -p 8054:80 -v /home/xj3hj2/docker/be-report:/var/www/html/be-report -v /opt/wwwroot/conf/:/var/www/conf/ be-report /bin/bash
# -p 8054:80 将本地的8054映射到容器的80端口
# -v 本地目录:容器目录 将本地的代码目录映射到容器中,默认可读可写
```
#运行后进入了容器的bash
```
cd /var/www/html/be-report && composer install
```
结束后,ctrl+p 再 ctrl+q 退出容器
退出容器后在本机配置nginx转发
sites-enabled/default 的
server dev.tob.ifchange.com 那一段
里增加:
```
location /v2/ {
proxy_pass http://report.ats.v2.dev.ifchange.com;
proxy_set_header Host $http_host;
}
```
conf.d/upstream.conf里增加
```
upstream report.ats.v2.dev.ifchange.com{
server localhost:8054;
}
```
测试:
http://dev.tob.ifchange.com/v2/account/cache
备注:
```
#查看所有容器,运行和未运行的
docker ps -a
#容器启动 停止
docker start/stop 容器名
#容器删除
docker rm 容器名
#查看所有镜像
docker images
#删除镜像
docker rmi 镜像名 //需要没有关联的容器
#tob-resume-service
cp bootstrap/autoload.php.example bootstrap/autoload.php
编辑 bootstrap/autoload.php 最前面 define(‘ENV‘, ‘dev‘)
```
原文地址:https://www.cnblogs.com/zeoblog/p/9435532.html