生产环境docker nginx+php8.0镜像
自定义创建php8.0镜像,创建dockerfile
bash
FROM php:8.0-fpm
# 安装系统依赖
RUN sed -i 's|http://deb.debian.org/debian|http://mirrors.aliyun.com/debian|g' /etc/apt/sources.list && \
apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
libonig-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo pdo_mysql mbstring zip exif pcntl bcmath \
&& pecl install redis \
&& docker-php-ext-enable redis
# 复制PHP配置文件(可选)
#COPY php.ini /usr/local/etc/php/
# 设置工作目录
WORKDIR /var/www/html
# 运行前的清理
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
在dockerfile目录下执行构建命令
bash
docker build -t php8.0 .
构建完docker images查看
创建docker-compose.yml文件
bash
version: '3.8'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./code:/var/www/html
networks:
- my_network
deploy:
replicas: 3
restart_policy:
condition: on-failure
php:
image: php:8.0-fpm
volumes:
- ./code:/var/www/html
networks:
- my_network
deploy:
replicas: 3
restart_policy:
condition: on-failure
networks:
my_network:
driver: overlay
使用docker stack deploy命令将Stack部署到Swarm集群中。
bash
docker stack deploy -c docker-compose.yml my_stack