docker php容器和本地作曲家问题 [英] docker php container and local composer issue
问题描述
好吧,我在Windows 10上使用wamp-server很长时间了,这很好,但是现在我想去使用docker并利用它的好处。
问题是我想在本地计算机上使用我的docker PHP解释器,因此根据此问题:
well I was using wamp-server on windows 10 for a long time and that was fine but now I want to go for docker and use its benefits. problem is I want to use my docker PHP interpreter on my local machine so according to this question:
我找到了使用这样的解决方案:
I've found a solution to use something like this:
docker exec -i php73_fpm php %*
在 php.bat
文件中,将其放在目录中并添加它到环境变量,看起来不错。
当我按下 php -v
时,它向我显示了我在docker上没有本地版本,所以应该没问题。
,直到我尝试使用作曲家为止。当我在CMD窗口中点击 php作曲家
时,就会显示错误消息:
in a php.bat
file, place it in a directory and add it to environment variables and that looks fine.
when i hit php -v
it shows me the version that i have on docker not locally so that should be fine.
until i tried to use composer. and as soon as i hit php composer
in a CMD window, it shows an error saying:
Could not open input file: C:\ProgramData\ComposerSetup\bin\composer.phar
这是因为我假设将 php.exe
路径更改为 php.bat
?和作曲家期望环境变量中的 php.exe
路径吗?
我如何强迫作曲家使用我的docker PHP容器而不是本地安装的容器?
this is because i changed php.exe
path to php.bat
i assume? and composer is expecting php.exe
path in environment variables?
how can i force composer to use my docker PHP container not the locally installed one?
编辑:我将在此处发布docker-compose.yml内容可能需要的情况:
i will post my docker-compose.yml content here in case that might be needed:
version: '3'
networks:
web_server:
driver: bridge
services:
nginx:
image: nginx
container_name: nginx_server
ports:
- "80:80"
- "443:443"
depends_on:
- php
- couchbase
command: [nginx-debug, '-g', 'daemon off;']
restart: unless-stopped
tty: true
volumes:
- ./docker/nginx/logs:/var/log/nginx
- ./docker/nginx/sites:/etc/nginx/conf.d
- ./src:/usr/share/nginx/html
networks:
- web_server
php:
container_name: php73_fpm
build:
context: ./docker/php-fpm
dockerfile: Dockerfile
working_dir: /usr/share/nginx/html
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: php73-fpm
SERVICE_TAGS: dev
ports:
- "9000:9000"
environment:
- COUCHBASE_HOST=couchbase
- COUCHBASE_BUCKET_NAME=default
- COUCHBASE_BUCKET_PASSWORD=
volumes:
- ./src:/usr/share/nginx/html
networks:
- web_server
couchbase:
image: couchbase
container_name: couchbase
ports:
- 8091:8091
- 8092:8092
- 8093:8093
volumes:
- ./docker/couchbase:/opt/couchbase/var
restart: unless-stopped
tty: true
networks:
- web_server
推荐答案
首先,此答案的灵感来自@soju有关在容器本身上安装作曲器的建议。
First of all this answer is inspired by @soju suggestion about installing composer on the container itself.
好原来我应该忘记我的本地作曲家并将其安装到我的容器中。所以我在PHP容器的Dockerfile中使用以下行安装了它:
well turned out I should have forget my local composer and install it to my container. so i installed it using this line in my php containter's Dockerfile:
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
然后我应该从环境变量中删除composer目录,这些目录是:
then i should have remove composer directories from environment variables, these directories are:
C:\Users\[windows-username-here]\AppData\Roaming\Composer\vendor\bin
C:\ProgramData\ComposerSetup\bin\composer.phar
创建另一个composer.bat文件,并将其放置在具有以下内容的位置:
create another composer.bat file and place it somewhere with this content:
docker exec -i php73_fpm composer %*
将文件路径添加到环境变量。
add file path to environment variables. and thats it.
现在当我使用 composer需要一些东西
时,它将把我的命令发送到 php73_fpm
docker容器并执行此操作。但应该在 docker-compose.yml
文件中使用该文件夹的卷,以便在创建 composer.json
会将其放置在本地计算机上的该目录中。
now when i use composer require something
it will send my command to the php73_fpm
docker container and do the job. but there should be a volume for the folder that i would use in the docker-compose.yml
file so when it creates the composer.json
it would place it in that directory on local machine.
这篇关于docker php容器和本地作曲家问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!