获取作曲家(php依赖关系管理器)在docker图像构建上运行 [英] Get composer (php dependency manager) to run on a docker image build

查看:219
本文介绍了获取作曲家(php依赖关系管理器)在docker图像构建上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我不再使用这种环境,所以我无法测试答案并接受一个答案。对不起,


TL; DR 你能指出一个使用作曲者处理PHP依赖关系的docker图像?



我发表的所有问题都是关于作者的php依赖工具 / strong>


我'我试图建立我自己的码头图像运行 wordpress作为作曲家依赖安装



我正在使用docker php图像作为基础构建码头图像,我需要做的是安装作曲家,并在图像创建时运行作曲家更新命令或者在图像构建时间(不知道两者是否可以)。



我可以通过手动执行所有步骤(运行docker图像,踩到它,并复制和粘贴每一步)。



但是当我将所有步骤放在Docker文件上时,我不会让作曲者编写文件。



一直试图得到一个最小的失败的例子一段时间,但我得到的是不是最小的。



我的测试由以下(链接到相关github repos下面)



Dockerfile

  NFORMATION ~~~#

#根据
#https://hub.docker.com/r/richarvey/nginx-php-fpm/
#和
#https://hub.docker.com/_/wordpress/

FROM php:7.0.2-apache

维护者Miquel Adell< miquel @ miqueladell。 COM>

ENV WORDPRESS_VERSION 4.4.1



#~~~ DEPENDENCIES ~~~#

#添加PHP存储库to apt source
RUN apt-get update \
&&& apt-get install -y \
libpng12-dev \
libjpeg-dev \
curl \
sed \
zlib1g-dev \
&& docker-php-ext-install \
zip \
mysqli

运行curl -sS https://getcomposer.org/installer | php - --install-dir = / usr / local / bin --filename = composer



#~~~ DIRS ~~~#

WORKDIR / var / www / html /



#~~~ WORDPRESS ~~~#

COPY文件/ composer.json composer.json
ONBUILD RUN作曲家更新

docker-compose.yml

  wordpress:
image:miqueladell / produce_wordpress_test
links:
- wordpress_db: mysql
环境:
- VIRTUAL_HOST = miqueladell.dev
- WORDPRESS_DB_NAME = wordpress
ports:
- 80

wordpress_db:
图片:miqueladell / mariadb-utf8mb4
环境:
- MYSQL_ROOT_PASSWORD =密码

我的测试如下


  1. 在一个包含上面粘贴的Docker文件

      docker build -t miqueladell / compiled_wordpress_test。 

    (日志中没有错误)


  2. 使用该映像通过在包含上面粘贴的docker-compose.yml的目录中运行以下命令来构建容器

      docker-compose up 

    (日志中没有错误)


  3. bash进入正在运行的容器,以便能够看到文件是否存在

      docker exec -i -t miqueladellv2_wordpress_1 bash 


  4. ls of / var / www / html

      root @ bff14367658b:/ var / www / html#ls -al 
    total 12
    drwxr-xr-x 2 www-data www-data 4096 Jan 19 10:50。
    drwxr-xr-x 5 root root 4096 Jan 19 10:50 ..
    -rw-r - r-- 1 root root 138 Jan 15 09:18 composer.json


您可以在步骤4中看到作曲家更新似乎根本没有运行。



我尝试使用

 code> RUN作曲家更新



相同的Docker文件上的$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $



如果我回到上一个测试步骤4,我在Docker容器的bash提示符上手动运行作曲家更新我得到:

  root @ bff14367658b:/ var / www / html#composer update 
加载包装信息的作曲家仓库
更新依赖关系(包括require-dev)
- 安装johnpbloch / wordpress-core-installer(0.2.1)
下载:100%

- 安装johnpbloch / wordpress(4.4 .1)
下载:100%

写入锁定文件
生成自动加载文件
root @ bff14367658b:/ var / www / html#ls -al
共24
drwxr-xr-x 4 www-data www-data 4096 Jan 19 11:12。
drwxr-xr-x 6 root root 4096 Jan 19 11:12 ..
-rw-r - r-- 1 root root 138 Jan 15 09:18 composer.json
- rw-r - r-- 1根根3718 Jan 19 11:12 composer.lock
drwxr-xr-x 4 root root 4096 Jan 19 11:12 vendor
drwxr-xr-x 5 root root 4096 Jan 19 11:12 wordpress
root @ bff14367658b:/ var / www / html#

这正是我期待在第4步的输出。



我会喜欢一些建议。感谢。



github链接到完整的文件




解决方案

今天遇到这个问题。



在图像中定义的一个。



似乎在构建过程中对目录所做的更改将被丢弃,如果目录被定义为卷。



以下是我工作的Dockerfile的一个例子。

  FROM richarvey / nginx-php-fpm 

#安装依赖项
运行apt-get update&& \
apt-get install curl nano&& \
curl -sS https://getcomposer.org/installer | php - --install-dir = / usr / local / bin --filename = composer

#添加更新nginx config
COPY conf / nginx-site.conf / etc / nginx /网站可用/ default.conf

#捆绑应用程序源
COPY应用程序/ / app

#安装应用程序依赖项
RUN cd / app& &安培; \
composer install --no-interaction

EXPOSE 80

然后在 conf / nginx-site.conf 我更新了我的应用程序的根目录(简称简称)

 服务器{
#...其余的nginx配置

root / app / public;

#...其余的nginx配置
}


NOTE: I no longer use this environment so there is no way for me to test the answers and accept one. I'm sorry.

TL;DR Can you point me to an example of a docker image that uses composer to handle PHP dependencies?

All my questions in this post are regarding composer the php dependency tool not docker-composer the successor of fig.

I'm trying to build my own docker image to run wordpress installed as a composer dependency.

I'm working on building a docker image using docker php image as a base and what I need to do is install composer and run a composer update command either on image creation time or on image build time (don't know if both would be ok).

I can run everything just fine by manually executing all the steps (running a docker image, bashing into it, and copying and pasting every step).

But when I put all that steps on a Dockerfile I don't get composer to write the files.

I've been trying to get a minimum failing example for some time but the one I've got is quite not mininum.

My test is composed of the following (links to the relevant github repos below)

Dockerfile

NFORMATION ~~~#

# based on
# https://hub.docker.com/r/richarvey/nginx-php-fpm/
# and
# https://hub.docker.com/_/wordpress/

FROM php:7.0.2-apache

MAINTAINER Miquel Adell <miquel@miqueladell.com>

ENV WORDPRESS_VERSION 4.4.1



#~~~ DEPENDENCIES ~~~#

# Add PHP repository to apt source
RUN apt-get update \
    && apt-get install -y \
        libpng12-dev \
        libjpeg-dev  \
        curl \
        sed \
        zlib1g-dev \
    && docker-php-ext-install \
        zip \
        mysqli

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer



#~~~ DIRS ~~~#

WORKDIR /var/www/html/



#~~~ WORDPRESS ~~~#

COPY files/composer.json composer.json
ONBUILD RUN composer update

docker-compose.yml

wordpress:
  image: miqueladell/composed_wordpress_test
  links:
    - wordpress_db:mysql
  environment:
    - VIRTUAL_HOST=miqueladell.dev
    - WORDPRESS_DB_NAME=wordpress
  ports:
   - "80"

wordpress_db:
  image: miqueladell/mariadb-utf8mb4
  environment:
     - MYSQL_ROOT_PASSWORD=password

My test is as follows

  1. Build an image executing this command in a directory containing the Dockerfile pasted above

    docker build -t miqueladell/composed_wordpress_test .
    

    (no errors in the log)

  2. Use that image to build a container by running the following command in a directory containing the docker-compose.yml pasted above

    docker-compose up
    

    (no errors in the log)

  3. bash into the running container to be able to see if the files are there

    docker exec -i -t miqueladellv2_wordpress_1 bash
    

  4. ls of /var/www/html

    root@bff14367658b:/var/www/html# ls -al
    total 12
    drwxr-xr-x 2 www-data www-data 4096 Jan 19 10:50 .
    drwxr-xr-x 5 root     root     4096 Jan 19 10:50 ..
    -rw-r--r-- 1 root     root      138 Jan 15 09:18 composer.json
    

You can see in step 4 that composer update seems to not have run at all.

I've tried using both

RUN composer update

and

ONBUILD RUN composer update

on Dockerfile with the same results.

If I go back to the previous step 4 of the test and I manually run composer update on the bash prompt of the docker container I get:

root@bff14367658b:/var/www/html# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing johnpbloch/wordpress-core-installer (0.2.1)
    Downloading: 100%

  - Installing johnpbloch/wordpress (4.4.1)
    Downloading: 100%

Writing lock file
Generating autoload files
root@bff14367658b:/var/www/html# ls -al
total 24
drwxr-xr-x 4 www-data www-data 4096 Jan 19 11:12 .
drwxr-xr-x 6 root     root     4096 Jan 19 11:12 ..
-rw-r--r-- 1 root     root      138 Jan 15 09:18 composer.json
-rw-r--r-- 1 root     root     3718 Jan 19 11:12 composer.lock
drwxr-xr-x 4 root     root     4096 Jan 19 11:12 vendor
drwxr-xr-x 5 root     root     4096 Jan 19 11:12 wordpress
root@bff14367658b:/var/www/html#

wich is exactly the output I was expecting on step 4

I would love some advice. Thanks.

github links to the full files

解决方案

I ran into this problem today.

What solved it for me was to use a different directory than the one that was defined in the image.

It seems like changes that are made to the directory during build process are discarded if the directory is defined as a volume.

Here's an example of my working Dockerfile

FROM richarvey/nginx-php-fpm

# Install dependencies
RUN apt-get update && \
    apt-get install curl nano && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add update nginx config
COPY conf/nginx-site.conf /etc/nginx/sites-available/default.conf

# Bundle app source 
COPY app/ /app

# Install app dependencies
RUN cd /app && \
    composer install --no-interaction 

EXPOSE 80

And then in conf/nginx-site.conf I updated the root for my application (shortened for brevity)

server {
    # ... the rest of your nginx config

    root /app/public;

    # ... the rest of your nginx config
}

这篇关于获取作曲家(php依赖关系管理器)在docker图像构建上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆