前言
Docker Compose 是一个工具,用于定义和运行多个 Docker 容器的应用程序。docker-compose类似于批处理,是一个命令行工具文件以docker-compose.yml命名。
docker-compose里重要的概念:Services Networks Volumes
Services:相当于container
Networks:相当于使用的网络
Volumes:数据持久化
build:构建镜像。可以指定 Dockerfile 的路径或者直接使用已有的镜像。
image:使用指定的镜像。
ports:指定容器端口映射,格式为 HOST_PORT:CONTAINER_PORT。
volumes:指定挂载卷,格式为 HOST_PATH:CONTAINER_PATH。
environment:设置环境变量,格式为 KEY=VALUE。
networks:指定容器连接的网络。
restart:指定容器重启策略,如 no, always, on-failure 等。
restart: always 是一个用于在容器停止后自动重新启动容器的指令。当容器出现任何错误或异常情况导致容器停止时,Docker将尝试自动重新启动容器。这个选项确保您的应用程序在意外关闭时能够自动恢复,并继续正常运行。
depends_on:指定容器之间的依赖关系。
command:覆盖容器默认的启动命令。
这些参数可以在 Docker Compose 配置文件中使用,如 docker-compose.yml。
docker-compose安装
安装docker-compose(官网:https://github.com/docker/compose/releases)
# 1. 下载docker-compose
curl -L https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
# 2. 赋权限
sudo chmod +x /usr/local/bin/docker-compose
#3. 查看版本
docker-compose -v
案例
常量文件
以下所有测试调配的服务常量管理文件
vi ./.env
# Choose storage path on your machine. For all storage systems
DATA_PATH_HOST=~/liuyuanshan/data
### WORKSPACE #############################################
WORKSPACE_TIMEZONE=PRC
### MYSQL #################################################
MYSQL_VERSION=8.0
MYSQL_DATABASE=default
MYSQL_USER=myuser
MYSQL_PASSWORD=myuserpassword
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=my-secret-pw
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
### REDIS #################################################
REDIS_PORT=6379
REDIS_PASSWORD=redispassword
### NGINX #################################################
NGINX_HOST_HTTP_PORT=80
NGINX_HOST_HTTPS_PORT=443
NGINX_HOST_WORDPRESS_PORT=8080
NGINX_HOST_LOG_PATH=./logs/nginx/
NGINX_SITES_PATH=./nginx/sites/
NGINX_PHP_UPSTREAM_CONTAINER=php-fpm
NGINX_PHP_UPSTREAM_PORT=9000
NGINX_SSL_PATH=./nginx/ssl/
NGINX_CODE_PATH=./html
NGINX_CONF_FILE=./nginx/nginx.conf
NGINX_DEFAULT_CONF_FILE=./nginx/default.conf
### PHP #################################################
PHP_PORT=9000
PHP_INI_FILE=./php/conf/php.ini
### RABBITMQ ##############################################
RABBITMQ_NODE_HOST_PORT=5672
RABBITMQ_MANAGEMENT_HTTP_HOST_PORT=15672
RABBITMQ_MANAGEMENT_HTTPS_HOST_PORT=15671
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
RABBITMQ_CHANNELS_ENABLED=./rabbitmq/management_agent.disable_metrics_collector.conf
Mysql编排简单版
停止并删除之前的容器(非必要)
docker stop $(docker container ls -qa)
docker rm $(docker container ls -qa)
docker-compose.yml
version: "3"
services:
# 定义服务名称
db:
# 使用指定的镜像
image: mysql:8.0
# 指定容器重启策略
restart: always
# 设置环境变量
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw
MYSQL_DATABASE: mydb
MYSQL_USER: myuser
MYSQL_PASSWORD: myuserpassword
# 指定容器端口映射
ports:
- "3306:3306"
# 指定挂载卷
volumes:
- mysql_data:/var/lib/mysql
# 指定容器连接的网络,自定义网络名称为backend
networks:
- backend
volumes:
mysql_data:
networks:
# 指定连接的网络为桥接模式
backend:
driver: bridge
启动服务
# 启动docker-compose文件
docker-compose up
# 或者启动并后台运行
docker-compose up -d
连接mysql,并授权远程连接
mysql -h 127.0.0.1 -u root -pmy-secret-pw
# 授权root用户远程连接
grant all privileges on *.* to 'root'@'%';
# 刷新
FLUSH PRIVILEGES;
Mysql编排(封装升级版本)
结合Dockerfile和.env文件封装整理
创建数据存放目录
# 创建数据存放目录
mkdir -p ~/liuyuanshan/data
创建Dockerfile文件
vi ./mysql/Dockerfile
# ARG 为MYSQL_VERSION变量设置默认值为latest
ARG MYSQL_VERSION=latest
# 先读取.env配置文件参数MYSQL_VERSION,读取不到则从ARG 设置参数中获取
FROM mysql:${MYSQL_VERSION}
# 定义一些说明信息,如作者
LABEL maintainer="1019213039@qq.com"
#####################################
# Set Timezone
#####################################
# UTC东八区时区,与国内差八小时
ARG TZ=UTC
# 增加Dockerfile的可读性,比如当前镜像的版本号
ENV TZ ${TZ}
# 在Dockerfile中设置镜像时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/
# COPY my.cnf /etc/mysql/conf.d/my.cnf
# 执行mysqld命令
CMD ["mysqld"]
# 暴露端口
EXPOSE 3306
编辑docker-compose.yml编排容器文件
vi ./docker-compose.yml
version: "3"
services:
# 定义服务名称
### MySQL ################################################ mysql:
build:
context: ./mysql
dockerfile: Dockerfile
restart: always
# 设置环境变量
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- TZ=${WORKSPACE_TIMEZONE}
# 指定容器端口映射
ports:
- "${MYSQL_PORT}:3306"
# 指定挂载卷
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
# 指定容器连接的网络,自定义网络名称为backend
networks:
- backend
volumes:
mysql:
networks:
# 指定连接的网络为桥接模式
backend:
driver: bridge
RabbitMQ编排
编辑Dockerfile文件 vi ./rabbitmq/Dockerfile
4369:epmd(Erlang Port Mapper Daemon),erlang服务端口
5672 :client端通信口
15672:HTTP API客户端,管理UI(仅在启用了管理插件的情况下)不一定会启动
25672:用于节点间通信(Erlang分发服务器端口)
FROM rabbitmq:alpine
LABEL maintainer="1019213039@qq.com"
RUN rabbitmq-plugins enable --offline rabbitmq_management
EXPOSE 4369 5671 5672 15671 15672 25672
编辑channels图形界面为可展示的
vi ./rabbitmq/management_agent.disable_metrics_collector.conf
management_agent.disable_metrics_collector = false
编排容器文件 vi ./docker-compose.yml
version: "3"
services:
### RabbitMQ #############################################
rabbitmq:
build: ./rabbitmq
ports:
- "${RABBITMQ_NODE_HOST_PORT}:5672"
- "${RABBITMQ_MANAGEMENT_HTTP_HOST_PORT}:15672"
- "${RABBITMQ_MANAGEMENT_HTTPS_HOST_PORT}:15671"
privileged: true
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
hostname: laradock-rabbitmq
volumes:
- ${DATA_PATH_HOST}/rabbitmq:/var/lib/rabbitmq
- ${RABBITMQ_CHANNELS_ENABLED}:/etc/rabbitmq/conf.d/management_agent.disable_metrics_collector.conf
#depends_on:
#- php
networks:
- backend
volumes:
rabbitmq:
networks:
backend:
driver: bridge
访问客户端地址
http://xx.xx.xx.xx:15672
Redis编排
redis配置文件
vi ./redis/redis.conf :
# Redis 6.2 配置文件
# 网络配置
bind 0.0.0.0
port 6379
# 安全配置
requirepass redispassword # 设置 Redis 服务密码
# 持久化配置
appendonly yes # 启用 AOF 持久化,默认为 no
appendfilename "appendonly.aof" # AOF 持久化文件名
dir /data # RDB 和 AOF 文件的保存路径
# 性能优化配置
maxmemory 2gb # 设置 Redis 最大内存限制,超出限制后 Redis 会根据所选策略删除一些键
maxmemory-policy allkeys-lru # 设置 Redis 内存淘汰策略,allkeys-lru 表示使用 LRU 策略删除所有键
创建Dockerfile文件 vi ./redis/Dockerfile
FROM redis:6.2-alpine
LABEL maintainer="1019213039@qq.com"
## For security settings uncomment, make the dir, copy conf, and also start with the conf, to use it
RUN mkdir -p /usr/local/etc/redis
COPY redis.conf /usr/local/etc/redis/redis.conf
# ARG 为REDIS_PASSWORD变量设置默认值为secret
ARG REDIS_PASSWORD=secret
# 声明参数,为了docker-compose里面可以动态配置
RUN sed -i "s/__REDIS_PASSWORD__/${REDIS_PASSWORD}/g" /usr/local/etc/redis/redis.conf
VOLUME /data
EXPOSE 6379
CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]
#CMD ["redis-server"]
编排容器文件 vi ./docker-compose.yml
version: "3"
services:
# 定义服务名称
### Redis ################################################
redis:
build:
context: ./redis
dockerfile: Dockerfile
restart: always
# 指定容器端口映射
ports:
- "${REDIS_PORT}:6379"
# 指定挂载卷
volumes:
- ${DATA_PATH_HOST}/redis:/data
# 指定容器连接的网络,自定义网络名称为backend
networks:
- backend
volumes:
redis:
networks:
# 指定连接的网络为桥接模式
backend:
driver: bridge
宿主机中连接redis容器服务
redis-cli -h 127.0.0.1 -p 3306
Nginx与PHP容器编排
创建文件夹
# https证书目录
mkdir -p ./nginx/ssl
# nginx的log日志目录
mkdir -p ./logs/nginx
# 代码存放目录
mkdir -p ./html
# php文件存放目录
mkdir -p ./php
mkdir -p ./php/conf
编排容器文件 vi ./docker-compose.yml
version: "3"
services:
### PHP #########################################
php:
build:
context: ./php
dockerfile: Dockerfile
restart: always
volumes:
- ${NGINX_CODE_PATH}:/var/www/html
- ${PHP_INI_FILE}:/usr/local/etc/php/php.ini:ro
networks:
- backend
### NGINX Server #########################################
nginx:
image: nginx:alpine
restart: always
volumes:
- ${NGINX_CODE_PATH}:/var/www/html
- ${NGINX_CONF_FILE}:/etc/nginx/nginx.conf
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
- ${NGINX_SSL_PATH}:/etc/nginx/ssl
ports:
- ${NGINX_HOST_HTTP_PORT}:80
- ${NGINX_HOST_HTTPS_PORT}:443
depends_on:
- php
networks:
- backend
networks:
backend:
driver: bridge
编辑nginx配置文件
vi ./nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
# Enable Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# PHP handling
server {
listen 80;
root /var/www/html/laravel/public;
index index.php index.html index.htm;
server_name www.liuyuanshan.top;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 8080;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name wordpress.liuyuanshan.top;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
upstream rabbitmq {
server lnmp-rabbitmq-1:5672;
}
server {
listen 15672;
server_name rabbitmq.liuyuanshan.top;
location / {
proxy_pass http://rabbitmq;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 将 'X-Forwarded-For' 传递给 RabbitMQ 服务器
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl;
root /var/www/html/laravel/public;
index index.php index.html index.htm;
server_name www.liuyuanshan.top;
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "script-src * 'unsafe-inline' 'unsafe-eval'";
add_header Strict-Transport-Security 'max-age=15552000';
add_header Referrer-Policy "no-referrer";
add_header X-Permitted-Cross-Domain-Policies 'none';
add_header X-Download-Options 'noopen';
add_header X-Frame-Options SAMEORIGIN;
ssl_certificate /etc/nginx/ssl/ssl_certificate.pem;
ssl_certificate_key /etc/nginx/ssl/ssl_certificate.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
编辑PHP的的Dockerfile文件
vi ./php/Dockerfile
FROM php:7.4-fpm
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libzip-dev \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libonig-dev \
libmcrypt-dev \
libxml2-dev \
git \
unzip \
curl
RUN docker-php-ext-install pdo_mysql mysqli opcache zip gd mbstring bcmath
# 安装 Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# pecl命令从PHP扩展社区库安装PHP扩展,并开启redis扩展
RUN pecl install redis && docker-php-ext-enable redis
# rabbitmq扩展安装rabbitmq-c和php依赖项
RUN apt-get update && \
apt-get install -y librabbitmq-dev && \
pecl install amqp && \
docker-php-ext-enable amqp
编辑PHP的php.ini配置文件
vi ./php/conf/php.ini
[PHP]
display_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
date.timezone = Asia/Shanghai
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.exception_ignore_args = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
variables_order = "GPCS"
request_order = "GP"
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[extension]
extension=amqp
extension=gd.so
extension=mysqli.so
zend_extension=opcache.so
extension=pdo_mysql.so
extension=redis
extension=sodium
extension=zip.so
[CLI Server]
cli_server.color = On
[Pdo_mysql]
pdo_mysql.default_socket=
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
[zend]
zend.assertions = -1
[tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[ldap]
ldap.max_links = -1
结合上文容器编排LNMP环境
编排容器文件
vi ./docker-compose.yml
version: "3"
services:
### MySQL ################################################
mysql:
build:
context: ./mysql
dockerfile: Dockerfile
restart: always
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- TZ=${WORKSPACE_TIMEZONE}
ports:
- "${MYSQL_PORT}:3306"
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
networks:
- backend
### Redis ################################################
redis:
build:
context: ./redis
dockerfile: Dockerfile
restart: always
ports:
- "${REDIS_PORT}:6379"
volumes:
- ${DATA_PATH_HOST}/redis:/data
networks:
- backend
### PHP #########################################
php:
build:
context: ./php
dockerfile: Dockerfile
restart: always
volumes:
- ${NGINX_CODE_PATH}:/var/www/html
- ${PHP_INI_FILE}:/usr/local/etc/php/php.ini:ro
networks:
- backend
### NGINX Server #########################################
nginx:
image: nginx:alpine
restart: always
volumes:
- ${NGINX_CODE_PATH}:/var/www/html
- ${NGINX_CONF_FILE}:/etc/nginx/nginx.conf
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
- ${NGINX_SSL_PATH}:/etc/nginx/ssl
ports:
- ${NGINX_HOST_HTTP_PORT}:80
- ${NGINX_HOST_HTTPS_PORT}:443
- ${NGINX_HOST_WORDPRESS_PORT}:8080
depends_on:
- php
networks:
- backend
### RabbitMQ #############################################
rabbitmq:
build: ./rabbitmq
ports:
- "${RABBITMQ_NODE_HOST_PORT}:5672"
- "${RABBITMQ_MANAGEMENT_HTTP_HOST_PORT}:15672"
- "${RABBITMQ_MANAGEMENT_HTTPS_HOST_PORT}:15671"
privileged: true
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
hostname: laradock-rabbitmq
volumes:
- ${DATA_PATH_HOST}/rabbitmq:/var/lib/rabbitmq
- ${RABBITMQ_CHANNELS_ENABLED}:/etc/rabbitmq/conf.d/management_agent.disable_metrics_collector.conf
depends_on:
- php
networks:
- backend
networks:
backend:
driver: bridge
注意事项:
代码中使用redis、mysql服务时,连接采用容器名称进行,例如:代码中DB_HOST=lnmp-mysql-1
以上完整编排文件已提交到github仓库
https://github.com/liuyuanshan11/lnmp_docker
PHP项目docker-compose文件使用案例
[root@localhost ~]# cat /opt/sumian-dockerfiles/docker-compose.yml
version: '3.7'
networks:
frontend:
driver: ${NETWORKS_DRIVER}
backend:
driver: ${NETWORKS_DRIVER}
volumes:
mysql:
driver: ${VOLUMES_DRIVER}
redis:
driver: ${VOLUMES_DRIVER}
phpmyadmin:
driver: ${VOLUMES_DRIVER}
services:
### Workspace Utilities ##################################
workspace:
image: registry.cn-shenzhen.aliyuncs.com/xxx:latest
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
- ./workspace/supervisor:/etc/supervisor
- ./workspace/crontab/:/etc/cron.d/
extra_hosts:
- "dockerhost:${DOCKER_HOST_IP}"
ports:
- "${WORKSPACE_SSH_PORT}:22"
tty: true
environment:
- PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
- DOCKER_HOST=tcp://docker-in-docker:2375
- http_proxy=${HTTP_PROXY}
- https_proxy=${HTTP_PROXY}
networks:
- frontend
- backend
links:
- docker-in-docker
deploy:
resources:
limits:
cpus: '0.60'
### PHP-FPM ##############################################
php-fpm:
image: registry.cn-shenzhen.aliyuncs.com/xxx:latest
volumes:
- ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
expose:
- "9000"
extra_hosts:
- "dockerhost:${DOCKER_HOST_IP}"
environment:
- PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
- DOCKER_HOST=tcp://docker-in-docker:2375
- FAKETIME=${PHP_FPM_FAKETIME}
- http_proxy=${HTTP_PROXY}
- https_proxy=${HTTP_PROXY}
depends_on:
- workspace
networks:
- backend
#links:
# - docker-in-docker
deploy:
resources:
limits:
cpus: '0.80'
### PHP Worker ############################################
php-worker:
build:
context: ./php-worker
args:
- PHP_VERSION=${PHP_VERSION}
- PHALCON_VERSION=${PHALCON_VERSION}
- INSTALL_PGSQL=${PHP_WORKER_INSTALL_PGSQL}
- INSTALL_BCMATH=${PHP_WORKER_INSTALL_BCMATH}
- INSTALL_PHALCON=${PHP_WORKER_INSTALL_PHALCON}
- INSTALL_SOAP=${PHP_WORKER_INSTALL_SOAP}
- INSTALL_ZIP_ARCHIVE=${PHP_WORKER_INSTALL_ZIP_ARCHIVE}
- INSTALL_MYSQL_CLIENT=${PHP_WORKER_INSTALL_MYSQL_CLIENT}
- INSTALL_AMQP=${PHP_WORKER_INSTALL_AMQP}
- INSTALL_CASSANDRA=${PHP_WORKER_INSTALL_CASSANDRA}
- INSTALL_GHOSTSCRIPT=${PHP_WORKER_INSTALL_GHOSTSCRIPT}
- INSTALL_SWOOLE=${PHP_WORKER_INSTALL_SWOOLE}
- INSTALL_TAINT=${PHP_WORKER_INSTALL_TAINT}
- INSTALL_FFMPEG=${PHP_WORKER_INSTALL_FFMPEG}
- INSTALL_GMP=${PHP_WORKER_INSTALL_GMP}
- PUID=${PHP_WORKER_PUID}
- PGID=${PHP_WORKER_PGID}
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
- ./php-worker/supervisord.d:/etc/supervisord.d
depends_on:
- workspace
extra_hosts:
- "dockerhost:${DOCKER_HOST_IP}"
networks:
- backend
### Laravel Horizon ############################################
laravel-horizon:
build:
context: ./laravel-horizon
args:
- PHP_VERSION=${PHP_VERSION}
- INSTALL_PGSQL=${PHP_FPM_INSTALL_PGSQL}
- INSTALL_BCMATH=${PHP_FPM_INSTALL_BCMATH}
- INSTALL_MEMCACHED=${PHP_FPM_INSTALL_MEMCACHED}
- INSTALL_SOCKETS=${LARAVEL_HORIZON_INSTALL_SOCKETS}
- INSTALL_CASSANDRA=${PHP_FPM_INSTALL_CASSANDRA}
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
- ./laravel-horizon/supervisord.d:/etc/supervisord.d
depends_on:
- workspace
extra_hosts:
- "dockerhost:${DOCKER_HOST_IP}"
networks:
- backend
### NGINX Server #########################################
nginx:
image: registry.cn-shenzhen.aliyuncs.com/xxx:latest
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
- ${NGINX_SITES_PATH}:/etc/nginx/sites-available
- ${NGINX_SSL_PATH}:/etc/nginx/ssl
environment:
- http_proxy=${HTTP_PROXY}
- https_proxy=${HTTP_PROXY}
ports:
- "${NGINX_HOST_HTTP_PORT}:80"
- "${NGINX_HOST_HTTPS_PORT}:443"
depends_on:
- php-fpm
networks:
- frontend
- backend
### MySQL ################################################
mysql:
build:
context: ./mysql
args:
- MYSQL_VERSION=${MYSQL_VERSION}
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- TZ=${WORKSPACE_TIMEZONE}
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
- ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
ports:
- "${MYSQL_PORT}:3306"
networks:
- backend
### Redis ################################################
redis:
image: registry.cn-shenzhen.aliyuncs.com/sleep-doctor/xxx:latest
volumes:
- ${DATA_PATH_HOST}/redis:/data
ports:
- "${REDIS_PORT}:6379"
networks:
- backend
### Redis Cluster ##########################################
redis-cluster:
build: ./redis-cluster
ports:
- "${REDIS_CLUSTER_PORT_RANGE}:7000-7005"
networks:
- backend
### RabbitMQ #############################################
rabbitmq:
build: ./rabbitmq
ports:
- "${RABBITMQ_NODE_HOST_PORT}:5672"
- "${RABBITMQ_MANAGEMENT_HTTP_HOST_PORT}:15672"
- "${RABBITMQ_MANAGEMENT_HTTPS_HOST_PORT}:15671"
privileged: true
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
hostname: laradock-rabbitmq
volumes:
- ${DATA_PATH_HOST}/rabbitmq:/var/lib/rabbitmq
depends_on:
- php-fpm
networks:
- backend
### phpMyAdmin ###########################################
phpmyadmin:
build: ./phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=${PMA_USER}
- MYSQL_PASSWORD=${PMA_PASSWORD}
- MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
ports:
- "${PMA_PORT}:80"
depends_on:
- "${PMA_DB_ENGINE}"
networks:
- frontend
- backend
### Docker-in-Docker ################################################
docker-in-docker:
image: docker:dind
privileged: true
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
expose:
- 2375
networks:
- backend
### REDISWEBUI ################################################
redis-webui:
build:
context: ./redis-webui
environment:
- ADMIN_USER=${REDIS_WEBUI_USERNAME}
- ADMIN_PASS=${REDIS_WEBUI_PASSWORD}
- REDIS_1_HOST=${REDIS_WEBUI_CONNECT_HOST}
- REDIS_1_PORT=${REDIS_WEBUI_CONNECT_PORT}
- REDIS_1_AUTH=${REDIS_PASSWORD}
networks:
- backend
ports:
- "${REDIS_WEBUI_PORT}:80"
depends_on:
- redis
### dev-sd-open-server
sd-open-server:
image: registry.cn-shenzhen.aliyuncs.com/xxx:dev
ports:
- "10000:10000"
working_dir: /app
networks:
- frontend
- backend
environment:
MYSQL_HOST: mysql
MYSQL_USERNAME: root
MYSQL_PASSWD: root
MYSQL_PORT: 3306
MYSQL_DATABASE: sd_open_service
REDIS_URL: "redis://:@redis:6379/10"
REDIS_HOST: "redis"
REDIS_PORT: 6379
REDIS_PASSWD: 'redispassword'
PORT: 10000
JWT_SECRET_KEY: "eyJ2Gc9OiJIUzI1NiIsI8N"
JWT_EXPIRATION_TIME: 7200
ACCESSTOKEN_EXPIRATION_TIME: 7200
[root@localhost ~]#