(1)完成Docker-compose的安装
下载Docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.22.0/docker-compose-uname -s-uname -m > /usr/local/bin/docker-compose
添加权限
sudo chmod +x /usr/local/bin/docker-compose
(2)Dockerfile编写
获取PHP基础镜像
(html,mysql参照上一次作业编写dockerfile)
nginx
FROM nginx:latest
MAINTAINER wang
#default.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html index.htm index.php; # 增加index.php
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ .php$ {
root /var/www/html; # 代码目录
fastcgi_pass phpfpm:9000; # 修改为phpfpm容器
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 修改为$document_root
include fastcgi_params;
}
}
phpfpm
FROM php:5.6-fpm
RUN apt-get update && apt-get install -y
libfreetype6-dev
libjpeg62-turbo-dev
libpng12*-dev
vim
&& docker-php-ext-install pdo_mysql
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
&& docker-php-ext-install gd
(3)使用Compose实现多容器运行机制
docker-compose.yml
version: "3"
services:
nginx:
build: ./nginx
ports:
- "80:80"
links:
- "phpfpm"
volumes:
- ./html/:/var/www/html/
- ./nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
phpfpm:
build: ./phpfpm
ports:
- "9000:9000"
volumes:
- ./html/:/var/www/html/
links:
- "mysql"
mysql:
build: ./mysql
ports:
- "3306:3306"
volumes:
- ./mysql/data/:/var/lib/mysql/
environment:
MYSQL_ROOT_PASSWORD : 123456
执行docker-compose
docker-compose up -d
(4)服务测试
访问index.html和index.php
创建数据库
建表
插入更新删除操作
(6)实验报告
困难:(1)Ubuntu莫名奇妙连不上网,后来换个网络就解决了。(2)Ubuntu关机后就再也打不开了,不得不重装。
感想:这次实践课花费快三天的时间,各种奇奇怪怪的配置问题,网上的教程又都比较琐碎,不得不占用我其他课程的时间,还是希望能简单点。。。