作曲家无法在Docker容器中工作:“ https://packagist.org/packages.json”不包含有效的JSON [英] Composer not working in docker container: "https://packagist.org/packages.json" does not contain valid JSON
问题描述
我有一个运行Symfony应用程序的Docker容器(运行良好)。容器内的Composer安装/需要命令(例如 composer需要批注
)通常会因以下错误而失败:
I have a docker container that's running a Symfony application (which works fine). Composer install/require commands (e.g. composer require annotations
) inside the container often fail with the following error:
[Seld\JsonLint\ParsingException]
"https://packagist.org/packages.json" does not contain valid JSON
Parse error on line 1:
\\\\\\u��n[7
���
^
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
我没有确实能够找到命令执行成功与否的模式,这似乎是完全随机的。我觉得这可能是缓存/联网的原因,因为它通常会工作一段时间,然后停止工作一段时间,但我不确定。 Composer命令可以在主机系统上正常运行(Ubuntu 17.10 / 18.04-认为此更新可能会有所帮助,但没有影响)。容器中的其他所有内容都可以正常工作。无论我打开容器中的外壳并在其中运行命令还是通过 docker-compose exec
运行命令,结果都是相同的。
I haven't really been able to find a pattern on when the commands succeed or not, it seems completely random. I feel like it might be a cache/networking thing, as it usually works for a while and then stops working for a while, but I'm not sure. Composer commands work fine on the host system (Ubuntu 17.10 / 18.04 - thought the update might help but doesn't make a difference). All other things composer in the container work fine. The result is the same whether I open a shell in the container and run the command there or run the command via docker-compose exec
.
这是我的Dockerfile:
Here's my Dockerfile:
FROM alpine:3.6
RUN apk add --update \
php7-fpm \
php7-apcu \
php7-ctype \
php7-curl \
php7-dom \
php7-gd \
php7-iconv \
php7-imagick \
php7-json \
php7-intl \
php7-mcrypt \
php7-mbstring \
php7-opcache \
php7-openssl \
php7-pdo \
php7-pdo_mysql \
php7-mysqli \
php7-xml \
php7-zlib \
php7-phar \
php7-tokenizer \
php7-session \
php7-xmlwriter \
php7-simplexml \
make \
curl
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
ADD symfony.ini /etc/php7/php-fpm.d/
ADD symfony.ini /etc/php7/cli/conf.d/
ADD symfony.pool.conf /etc/php7/php-fpm.d/
CMD ["php-fpm7", "-F"]
WORKDIR /var/www/symfony
EXPOSE 9000
我运行它通过docker-compose,将卷安装到/ var / www / symfony并公开端口:
I run it via docker-compose, which mounts a volume to /var/www/symfony and exposes the port:
version: '2.1'
services:
php:
build: .
volumes:
- ./symfony:/var/www/symfony
ports:
- 9000:9000
如何使它工作?我不知道需要进行任何设置才能使作曲家能够正确连接吗?
How do I get this to work? Any setting I don't know of that I need to activate for composer to be able to connect properly?
推荐答案
您可以添加这到您的DockerFile:
You can add this to your DockerFile :
RUN composer config --global repo.packagist composer https://packagist.org
这篇关于作曲家无法在Docker容器中工作:“ https://packagist.org/packages.json”不包含有效的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!