将docker-compose.yml中的软件包安装到docker容器中 [英] install packages from docker-compose.yml into docker container
问题描述
我是docker和docker-compose的初学者,需要您的帮助。
I am a beginner with docker and docker-compose and i need your help.
我正在使用docker-compose开发PHP-NGINX-PostgresSQL symfony开发环境。
I'm making PHP-NGINX-PostgresSQL symfony developement environment using docker-compose.
这里是:
web:
image: nginx:1.13.5
ports:
- "80:80"
volumes:
- ./html:/html
- ./site.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./html:/html
links:
- postgres
postgres:
image: postgres:9.6.5
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: postgres
现在,我会想要将php7.2-intl安装到我的php容器中。所以我想执行以下命令:
Now, i would like to install php7.2-intl into my php container. So i would like to execute something like :
$ sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install php7.2-intl
你能帮我吗?我真的很困,也没有Dockerfile文件,只有docker-compose.yml文件。
Could you help me? I'm really stuck and also I dont have a Dockerfile file, just a docker-compose.yml file.
推荐答案
一个具有intl扩展名的PHP docker容器,您需要扩展正式的PHP映像。
To get a PHP docker container with the intl extension, you need to extend the official PHP image.
为此,声明使用您自己的 Dockerfile
用于 docker-compose.yml中的PHP映像:
To do so, declare the use of your own Dockerfile
for your PHP image in docker-compose.yml
:
services:
php:
# Remove this line
# image: php:7-fpm
# Add this one instead
build: './docker/php'
# ...
然后,添加以下 Dockerfile
文件添加到 docker / php
文件夹中:
Then, add the following Dockerfile
file to the docker/php
folder:
FROM php:7.1-fpm
RUN apt-get update && apt-get install -y \
libicu-dev \
&& docker-php-ext-install \
intl \
&& docker-php-ext-enable \
intl
您现在可以运行 docker-compose build
使您的PHP容器使用Intl扩展名构建。
You can now run docker-compose build
to get your PHP container built with the Intl extension.
一些注意事项:
- 我更愿意明确说明我使用的PHP版本(此处为 7.1.x),而不是用<$ c定义的更通用的 7.x $ c> php:7-fpm 。
- 我更喜欢使用
docker-php-ext-install $ c $ PHP官方映像提供的c>和
docker-php-ext-enable
命令实用程序(请参见 PHP映像文档)。
- I prefer to explicitly tell which PHP version I use (here "7.1.x") rather than the more generic "7.x" you defined with
php:7-fpm
. - I preferred to use the
docker-php-ext-install
anddocker-php-ext-enable
command utilities provided by the PHP official image (see "How to install more PHP extensions" section in the PHP image documentation).
这篇关于将docker-compose.yml中的软件包安装到docker容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!