我首先阅读了这些链接
但是作为docker的初学者。它没有帮助我。
您需要了解的内容:
./ docker-compose.yml
###############################################################################
# Generated on phpdocker.io #
###############################################################################
version: "3.1"
services:
mailhog:
image: mailhog/mailhog:latest
container_name: myapp-mailhog
ports:
- "8081:8025"
redis:
image: redis:alpine
container_name: myapp-redis
mariadb:
image: mariadb:10.4
container_name: myapp-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=myapp
- MYSQL_USER=forge
- MYSQL_PASSWORD=forge
ports:
- "8083:3306"
webserver:
image: nginx:alpine
container_name: myapp-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
php-fpm:
build: phpdocker/php-fpm
container_name: myapp-php-fpm
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini
./ phpdocker / nginx / nginx.conf
server {
listen 80 default;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
root /application/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
./ phpdocker / php-fpm / Dockerfile (稍作修改以添加mysql_client而不在第二个RUN命令中安装git)
FROM phpdockerio/php73-fpm:latest
WORKDIR "/application"
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install \
php7.3-mysql php-redis php7.3-sqlite3 php-xdebug php7.3-bcmath php7.3-bz2 php7.3-gd \
git \
mysql-client \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
./ php-ini-overrides.ini
upload_max_filesize = 100M
post_max_size = 108M
我尝试使用network_mode: host
,但它使网络服务器以Exit 1
停止
答案 0 :(得分:2)
好吧,但是请记住,mysql / mariadb中的localhost意味着可以通过本地unix套接字进行访问。有一些在容器之间共享它们的方法。
答案 1 :(得分:1)
@ F.Maden给了我正确的方向。我接受了他的回答,但这是我的详细说明。
基本上他说过,我需要在我的服务 mariadb 和 php-fpm
之间共享 mysqld.sock第一步是在两个服务之间共享一个文件夹。因为我已经
具有包含docker配置/application
的{{1}},我将重用此文件。
我必须创建一个自定义my.cnf文件来编辑默认的 mariadb 配置配置并添加一个自定义套接字路径:
./ phpdocker / mariadb / my.cnf
/application/phpdocker
./ docker-compose.yml
[mysql]
socket = /application/phpdocker/shared/mysqld.sock
[mysqld]
socket = /application/phpdocker/shared/mysqld.sock
mariadb:
image: mariadb:10.4
container_name: myapp-mariadb
working_dir: /application
volumes:
- .:/application
- ./phpdocker/mariadb/my.cnf:/etc/mysql/my.cnf # notice this line
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=myapp
- MYSQL_USER=forge
- MYSQL_PASSWORD=forge
ports:
- "8083:3306"
,其中mariadb可以创建 mysqld.sock (我无法以755启动mariadb。对于我来说,这是仅用于本地而不用于生产,这样就可以了) 从终端
./phpdocker/shared
从终端
$ mkdir ./phpdocker/shared && chmod 777 ./phpdocker/shared
在容器中一次
$ docker-compose up -d --force-recreate --build
$ docker exec -it -u $(id -u):$(id -g) myapp-php-fpm /bin/bash