我有一个简单的Dockerfile
配置php:7.2-fpm
正在引用它docker-compose.yml
。我想删除Dockerfile
位于php/Dockerfile
并将命令集成到我的docker-compose-yml
文件中。
这是我的php/Dockerfile
:
FROM php:7.2-fpm RUN docker-php-ext-install mysqli
这是我的docker-compose.yml
,它启动了 php-fpm、nginx、letencrypt certbot、mysql 和 phpmyadmin:
version: '3'
services:
php:
container_name: dev_php
build:
context: ./php
ports:
- 9000:9000
volumes:
- ./website:/website
- ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
environment:
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
nginx:
container_name: dev_nginx
image: nginx:1.13.8
ports:
- 80:80
- 443:443
volumes:
- ./website:/website
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
depends_on:
- php
- mysql
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
container_name: dev_certbot
image: certbot/certbot
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
mysql:
container_name: dev_mysql
image: mysql:5.7
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- ./mysql:/docker-entrypoint-initdb.d
由于我的php/Dockerfile比较简单,我想我可以这样做:
但这是行不通的。当我使用我的项目启动时,docker-compose up我可以看到dev_php(PHP 容器的名称)执行了一堆我通常不会看到的任务,然后它继续安装,mysqli但在使用exit code 0.
想法?
largeQ