简体   繁体   English

将docker-compose.yml中的软件包安装到docker容器中

[英]install packages from docker-compose.yml into docker container

I am a beginner with docker and docker-compose and i need your help. 我是docker和docker-compose的初学者,我需要你的帮助。

I'm making PHP-NGINX-PostgresSQL symfony developement environment using docker-compose. 我正在使用docker-compose制作PHP-NGINX-PostgresSQL symfony开发环境。

Here it is : 这里是 :

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

Now, i would like to install php7.2-intl into my php container. 现在,我想将php7.2-intl安装到我的php容器中。 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

Could you help me? 你可以帮帮我吗? I'm really stuck and also I dont have a Dockerfile file, just a docker-compose.yml file. 我真的卡住了,我也没有Dockerfile文件,只是一个docker-compose.yml文件。

To get a PHP docker container with the intl extension, you need to extend the official PHP image. 要获得具有intl扩展名的PHP docker容器,您需要扩展官方PHP映像。

To do so, declare the use of your own Dockerfile for your PHP image in docker-compose.yml : 要做到这一点,声明使用自己的Dockerfile在你的PHP像docker-compose.yml

services:
  php:
    # Remove this line
    # image: php:7-fpm

    # Add this one instead
    build: './docker/php'
    # ...

Then, add the following Dockerfile file to the docker/php folder: 然后,将以下Dockerfile文件添加到Dockerfile docker/php文件夹:

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

You can now run docker-compose build to get your PHP container built with the Intl extension. 您现在可以运行docker-compose build来获取使用Intl扩展docker-compose build的PHP容器。

A few notes: 几点说明:

  • 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 . 我更喜欢明确告诉我使用哪个PHP版本(这里是“7.1.x”)而不是你用php:7-fpm定义的更通用的“7.x” php:7-fpm
  • I preferred to use the docker-php-ext-install and docker-php-ext-enable command utilities provided by the PHP official image (see "How to install more PHP extensions" section in the PHP image documentation ). 我更喜欢使用PHP官方映像提供的docker-php-ext-installdocker-php-ext-enable命令实用程序(请参阅PHP映像文档中的“如何安装更多PHP扩展”部分)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM