TL; DR 使用相同的图像,我在运行docker run和docker-compose时会得到不同的结果。
我正在使用official php docker image,我想安装一组扩展程序。这是我的FROM php:7.1.2-fpm
# Install software and dependencies (for extensions)
RUN apt-get update \
&& apt-get install -qy \
libcurl4-gnutls-dev \
libpng-dev \
libicu-dev \
mcrypt \
libmcrypt-dev \
libxml2-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
git \
nodejs
# Install required PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-enable gd
# Install and setup composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
# Cleanup tasks
RUN apt-get clean
:
gd
如您所见,我正在尝试安装docker build
库。这实际上取自他们的例子。在运行Step 1/5 : FROM php:7.1.2-fpm
---> 7191c638ed10
Step 2/5 : RUN apt-get update && apt-get install -qy libcurl4-gnutls-dev libpng-dev libicu-dev mcrypt libmcrypt-dev libxml2-dev libfreetype6-dev libjpeg62-turbo-dev libpng12-dev git nodejs
---> Using cache
---> 1f53f9211603
Step 3/5 : RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd && docker-php-ext-enable gd
---> Using cache
---> 4598a07d9fca
Step 4/5 : RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
---> Running in 89c18c9ddf40
All settings correct for using Composer
Downloading...
Composer (version 1.4.0) successfully installed to: /var/www/html/composer.phar
Use it: php composer.phar
---> 059a1da3bb1a
Removing intermediate container 89c18c9ddf40
Step 5/5 : RUN apt-get clean
---> Running in 66c9cb68f684
---> f9543fa8b6e3
Removing intermediate container 66c9cb68f684
Successfully built f9543fa8b6e3
时,我看到它运行配置和安装步骤(步骤3/5):
docker run
当我现在在机器上执行简单gd
和ssh时,$ php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
扩展程序可用:
docker build
现在,这是有趣的部分:当我构建(docker-compose up
)图像然后使用docker-compose up
运行容器时,未安装扩展名。
我把它缩小到docker-compose build {servicename}
是问题,因为我做了很多不同的事情:
docker run {image-ID}
+ docker-compose down
- >扩展可用dockerfile
)
docker-compose.yml
尝试使用远程注册表,甚至构建图像,然后在docker-compose.yml
- >中输入本地图像。相同的结果更新
我的version: '2'
services:
php:
# this is the variant with the registry
image: registry.example.com/devops/php:base-php-fpm
volumes:
- './src:/code'
- './config/php:/usr/local/etc/php'
links:
- mysql
depends_on:
- mysql
nginx:
image: nginx:1.10
ports:
- "80:80"
volumes:
- './src:/code'
- './config/nginx:/etc/nginx'
depends_on:
- php
links:
- php
mysql:
image: mysql
ports:
- "3306:3306"
:
{{1}}
答案 0 :(得分:0)
原来是配置文件的卷挂载到php的config文件夹中 - 只能在我的compose文件中找到。它会覆盖自动生成的PHP配置。
其中一件事让你忙碌了一整天而没有提供最微小的功能......
感谢您的帮助,伙计们!