安装好nginx, php, mysql, redis,放在宿主机。data下的项目“blog”就可以运行了
nginx
docker pull nginx:1.12.2 //下载镜像
docker run -d -p 8080:80 --name nginx_1.12 -v ./data:/var/www/html -v ./data/sites/:/etc/nginx/conf.d/ --link phpfpm_7.2:phpfpm nginx:1.12.2
-p 8000宿主机端口:80容器端口
--name 容器名称
-v 宿主机路径与容器路径映射,在宿主机修改目录内的内容 容器对应路径下也会变化,/var/www/html:项目 /etc/nginx/conf.d/:nginx的端口配置文件
--link 链接其他容器 phpfpm_7.2:phpfpm,容器名为“phpfpm_7.2”作为phpfpm
nginx:1.12.2 使用的镜像
宿主机./data/sites/下的default.conf
server {
listen 80;
server_name localhost;
root /var/www/html/blog/public;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /dev/null;
access_log /var/www/html/blog/storage/nginx.blog.access.log main;
error_log /var/www/html/blog/storage/nginx.blog.error.log warn;
#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 /usr/share/nginx/html;
}
location / {
index index.html index.htm index.php l.php;
try_files $uri $uri/ /index.php?$query_string;
autoindex on;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass phpfpm_7.2:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
php
docker pull php:7.2-fpm
docker run -d -v ./data:/var/www/html -v ./data/php/php.ini:/usr/local/etc/php/php.ini:ro -p 9000:9000 --link mysql_5.7:mysql --name phpfpm_7.2 php:7.2-fpm
进入容器
docker exec -it phpfpm_7.2 /bin/bash
使用“php -m”查看已安装的插件,需要安装“pdo_mysql”
docker-php-ext-install pdo_mysql
mysql
docker pull mysql:5.7
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=11111111 --name mysql_5.7 mysql:5.7
redis
docker pull redis:5.0.3
docker run -d -p 6379:6379 -v ./conf/redis.conf:/usr/local/etc/redis/redis.conf:ro redis-server --appendonly yes
-p 6379:6379 : 将容器的6379端口映射到主机的6379端口
redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置
网友评论