对于安装GitHub上start最多的dnmp环境的步骤及感悟
https://github.com/yeszao/dnmp/blob/master/README.md
- 在服务器上装docker与docker-compose
注意:安装docker-compose的时候选择官方版本安装(虽然慢但是请等等),我操作时出现过国内镜像地址安装但 执行docker-compose --version 安装不成功,又换成官方版本安装
- 安装git (推荐源码安装)
- 在
/usr/local/
目录下git clone https://github.com/yeszao/dnmp.git
- 执行
cd dnmp # 进入项目目录
cp env.sample .env # 复制环境变量文件
cp docker-compose.sample.yml docker-compose.yml # 复制 docker-compose 配置文件。默认启动3个服务:
# Nginx、PHP7和MySQL8。要开启更多其他服务,如Redis、
# PHP5.6、PHP5.4、MongoDB,ElasticSearch等,请删 # 除服务块前的注释
修改 docker-compose.yml 添加配置 安装portainer(docker容器可视化面板)
并且在
/usr/local/dnmp/data/
目录下新建portainer目录与portainer_chinese目录
portainer_chinese目录是为了汉化portainer的包,我安装的是2.16.2版本
在https://imnks.com/3406.html 网址下载汉化包并将其内容拷贝至portainer_chinese
目录
portainer:
image: portainer/portainer:latest
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:cached
- ${DATA_DIR}/portainer/:/data:cached
- ${DATA_DIR}/portainer_chinese:/public
cap_add:
- SYS_PTRACE
networks:
- default
在此基础上我们还要添加supervisord的容器,但由于自带的supervisord的容器里没有PHP环境无法执行PHP命令,我们可以把以下内容添加至
docker-compose.yml
php-worker:
build:
context: ./services/php-worker
args:
PHP_VERSION: php:${PHP_VERSION}-alpine
CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL}
PHP_EXTENSIONS: ${PHP_EXTENSIONS}
TZ: "$TZ"
container_name: php-worker
ports:
- "${SUPERVISOR_HOST_PORT_C}:9001"
volumes:
- ${SOURCE_DIR}:/www/:rw
- ${DATA_DIR}/composer:/tmp/composer
- ${SUPERVISOR_LOG}:/var/log/supervisor/:rw
- ${SUPERVISOR_CONFIG}:/etc/supervisor/conf.d/:rw
- ${SUPERVISOR_CONF_FILE}:/etc/supervisor/supervisord.conf:ro
command:
- /bin/sh
- -c
- |
supervisord -n -c /etc/supervisor/supervisord.conf
restart: always
cap_add:
- SYS_PTRACE
networks:
- default
参考 https://www.chenqicheng.com/article/52 (第一行的docker-compser我给删掉了),并且在
/usr/local/dnmp/services/
目录下 新建php-worker
目录,将/usr/local/dnmp/services/php
目录下的extensions
目录拷贝至php-worker
目录,然后在php-worker
目录下新建Dockerfile文件并将以下代码拷贝进去(以下代码与参考网址一致)
ARG PHP_VERSION
FROM ${PHP_VERSION}
ARG TZ
ARG PHP_EXTENSIONS
ARG CONTAINER_PACKAGE_URL
RUN if [ $CONTAINER_PACKAGE_URL ] ; then sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories ; fi
#php容器内安装supervisor
RUN apk update \
&& apk upgrade \
&& apk add supervisor \
&& apk --no-cache add tzdata \
&& cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
&& echo "$TZ" > /etc/timezone \
&& rm -rf /var/cache/apk/*
COPY ./extensions /tmp/extensions
WORKDIR /tmp/extensions
RUN chmod +x install.sh \
&& sh install.sh \
&& rm -rf /tmp/extensions
ADD ./extensions/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions
RUN apk --no-cache add tzdata \
&& cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
&& echo "$TZ" > /etc/timezone
# Fix: https://github.com/docker-library/php/issues/240
RUN apk add gnu-libiconv libstdc++ --no-cache --repository http://${CONTAINER_PACKAGE_URL}/alpine/edge/community/ --allow-untrusted
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
# Install composer and change it's cache home
RUN curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
&& chmod +x /usr/bin/composer
ENV COMPOSER_HOME=/tmp/composer
# php image's www-data user uid & gid are 82, change them to 1000 (primary user)
RUN apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
WORKDIR /www
至此,执行 docker-compose up -d
启动
Portainer面板使用
1.阿里云服务器安全组打开9000端口
2.主机IP:9000在浏览器访问 并设置账号密码(账号密码要记住)
3.进入Portainer面板(完成汉化的)
如果需要使用composer建议进入容器内部使用
安装扩展建议
文章参考网址 :
Portainer汉化
supervisord+php容器创建
完结,撒花~