我正在Mac电脑上本地制作laravel (流明)应用程序。
docker-compose.yml:
version: "3.9"
services:
# LibreOffice Service
libreoffice:
image: lscr.io/linuxserver/libreoffice:latest
container_name: libreoffice
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ./:/home
ports:
- "3000:3000"
restart: unless-stopped
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge正如您在yml文件中看到的那样,我正在nginx容器中运行我的应用程序,一切都很好。
但当我试图运行命令时:
docker exec libreoffice soffice --headless --invisible --convert-to pdf --outdir "home/public/tmp" "home/public/tmp/hi.docx"在我的应用程序中,它引发以下错误:
sh: 1: docker: not found在浪费了几天时间之后,我发现它在nginx容器中寻找nginx,而不是在我的本地计算机上。意味着我在应用程序中定义的所有其他服务都不能在我的应用程序中访问,因为my application = nginx container.但是为什么呢?那我该怎么办呢?如何创建环境以访问应用程序中的其他服务?
我的大问题
为什么它甚至在容器中运行整个应用程序?当我使用nginx运行app时,我的应用程序断开了与本地环境的连接,并试图在nginx容器中查找所有其他容器。例如,如果我需要转换一些文件,为了进行转换,我需要libreoffice服务在后台运行。当我尝试用soffice --headless --invisible --convert-to pdf --outdir命令连接它时,它会抛出一个错误,如下所示:
sh: 1: soffice: not found因为它是在nginx容器中寻找nginx,而不是在本地docker中。如果是这样,那么我如何使用nginx运行我的应用程序呢?我需要在nginx container中运行所有其他容器吗?这怎么可能呢?
发布于 2022-10-07 11:16:26
经过进一步的研究,我发现从另一个容器访问容器并在内部运行一些命令是不可能的。
解决这一问题的一些办法:
REST API连接.REST API来访问并运行1. Removing `libreoffice` service as container and installing it to `php` container with linux command in `Dockerfile`:运行apt-get更新&& apt-获取安装-y libreoffice
2. Command can be run remotely using ssh. Check [this](https://stackoverflow.com/questions/18502945/how-to-execute-a-remote-command-over-ssh-with-arguments) topic (I don't recommend)https://stackoverflow.com/questions/73947372
复制相似问题