我有一个在 Apache 下运行且没有 docker 的项目。但是,在这个项目中,我有一个 PDF 导出,我想在 docker 容器中调用它。你是怎样做的?
这是我的docker-compose.yaml
:
version: "3.3"
services:
php:
image: registry.gitlab.com/nodevo/keneo/php:latest
volumes:
- .:/srv:rw,cached
- ~/.ssh/id_rsa:/root/.ssh/id_rsa:ro
- ~/.composer:/tmp
browsershot:
image: ouranoshong/browsershot
links:
- chrome
chrome:
build: ./docker/chrome
cap_add:
- SYS_ADMIN
ports:
- '9223:9222'
Browsershot 服务下载 PDF 并具有 node 和 npm。为此,它模拟了一个浏览器,所以我有一个 chrome 服务,但我不知道它是否是正确的方法。
这两个命令在终端中工作:
docker-compose run --rm browsershot node -v
docker-compose run --rm browsershot npm -v
但是,Browsershot 需要可执行节点和 npm 的路径,这两个命令突然变成了上面的 2 个命令:
/**
* @param string $nodePath
* @param string $npmPath
*/
public function __construct(string $nodePath, string $npmPath)
{
$this->browserShot = new Browsershot();
$this->browserShot
->setNodeBinary($nodePath)
->setNpmBinary($npmPath)
->showBackground()
->setOption('fullPage', true)
->setOption('args', ['--disable-web-security'])
->emulateMedia('screen')
;
}
变量$nodePath
isdocker-compose run --rm browsershot node
和变量$npmPath
id docker-compose run --rm browsershot npm
。此代码适用于我的本地机器中的可执行文件,例如/usr/local/bin/node
和/usr/local/bin/npm
。
但是,当我使用 docker 命令启动导出时,出现此错误:
HTTP 500 Internal Server Error
The command "PATH=$PATH:/usr/local/bin NODE_PATH=`docker-compose run --rm browsershot node docker-compose run --rm browsershot npm root -g` docker-compose run --rm browsershot node '/media/vdufour/DATA/Sites/keneo/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/639306024-0718333001579852859\/index.html","action":"pdf","options":{"args":["--disable-web-security"],"viewport":{"width":800,"height":600},"fullPage":true,"emulateMedia":"screen","delay":2000,"displayHeaderFooter":false,"printBackground":true}}'" failed.
Exit Code: 1(General error)
Working directory: /media/vdufour/DATA/Sites/keneo/public
Output:
================
Error Output:
================
Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.