我尝试使用fpm为this项目运行php应用程序。我正在尝试使nginx图像运行基于fpm的解决方案。我的docker-compose.yml
是:
version: '2'
services:
# apache based images
# A base image for apache - based moodle builds
moodle_apache_base:
build:
context: .
dockerfile: dockerfiles/apache/Dockerfile_base
image: ellakcy/moodle:apache_base
# Mysql running variant
moodle_mysql_db:
image: mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "${MOODLE_DB_NAME}"
MYSQL_USER: '${MOODLE_MYSQL_USER}'
MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
moodle_mysql:
build:
context: .
dockerfile: dockerfiles/apache/Dockerfile_mysql
image: ellakcy/moodle:mysql_maria_apache
links:
- "moodle_mysql_db:moodle_db"
- "moodle_apache_base"
ports:
- "6080:80"
environment:
MOODLE_DB_HOST: "moodle_mysql_db"
MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
MOODLE_ADMIN: "${MOODLE_ADMIN}"
MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
MOODLE_URL: "http://0.0.0.0:6080"
# postgresql running variant
moodle_psql_db:
image: postgres
environment:
POSTGRES_DB: "${MOODLE_DB_NAME}"
POSTGRES_USER: '${MOODLE_MYSQL_USER}'
POSTGRES_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
moodle_psql:
build:
context: .
dockerfile: dockerfiles/apache/Dockerfile_postgrtesql
image: ellakcy/moodle:postgresql_apache
links:
- "moodle_psql_db:moodle_db"
- "moodle_apache_base"
ports:
- "6082:80"
environment:
MOODLE_DB_HOST: "moodle_psql_db"
MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
MOODLE_ADMIN: "${MOODLE_ADMIN}"
MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
MOODLE_URL: "http://0.0.0.0:6082"
# Testing mariadb support
moodle_maria_db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "${MOODLE_DB_NAME}"
MYSQL_USER: '${MOODLE_MYSQL_USER}'
MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
moodle_maria:
image: ellakcy/moodle:mysql_maria_apache
links:
- "moodle_mysql"
- "moodle_maria_db:moodle_db"
ports:
- "6081:80"
environment:
MOODLE_DB_HOST: "moodle_maria_db"
MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
MOODLE_ADMIN: "${MOODLE_ADMIN}"
MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
MOODLE_URL: "http://0.0.0.0:6081"
#Alpine fpm based images
#Basic alpine fpm image
alpine_fpm_base:
build:
context: .
dockerfile: dockerfiles/fpm_alpine/Dockerfile_base
image: ellakcy/moodle:alpine_fpm_base
moodle_mysql_alpine_db:
image: mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "${MOODLE_DB_NAME}"
MYSQL_USER: '${MOODLE_MYSQL_USER}'
MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
# Mysql Enabled image
nginx:
image: nginx:alpine
ports:
- "7070:80"
volumes:
- './conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
links:
- 'moodle_mysql_alpine'
volumes_from:
- 'moodle_mysql_alpine'
moodle_mysql_alpine:
build:
context: .
dockerfile: dockerfiles/fpm_alpine/Dockerfile_mysql
image: ellakcy/moodle:mysql_maria_fpm_alpine
links:
- "moodle_mysql_alpine_db:moodle_db"
- "alpine_fpm_base"
environment:
MOODLE_DB_HOST: "moodle_mysql_alpine_db"
MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
MOODLE_ADMIN: "${MOODLE_ADMIN}"
MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
MOODLE_URL: "http://0.0.0.0:7070/moodle_mysql"
nginx配置是:
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
gzip on;
gzip_disable "msie6";
client_max_body_size 10000M;
server {
listen 80;
root /var/www/www;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout 600;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
fastcgi_pass moodle_mysql_alpine:9000;
}
}
}
但无论我试图做什么都没用,我无法让我的moodle_mysql_alpine
通过nginx获得服务。你们的伙伴们有一个想法,我怎么能让它得到服务?还要保留minf,我不关心在我的本地filesysytem中保留卷,因为这个文件旨在构建和运行图像只是为了将它们上传到图像存储库。
答案 0 :(得分:0)
最后我在根文件夹上做错了。它是/var/www/html
而不是/var/www/www
。所以nginx正确地提示我进入404页面,因为没有安装文件/卷。