0

I have used docker-compose to dockerise a python app dependent on a database which works fine. The python app generates a powerpoint file which it stores in /tmp within the container. It then needs to be converted to pdf for the dockerised frontend to render it. I intend to do this using a dockerised libreoffice image https://hub.docker.com/r/domnulnopcea/libreoffice-headless/

The libreoffice container is run as follows

sudo docker run -v /YOUR_HOST_PATH/:/tmp libreoffice-headless libreoffice --headless --convert-to pdf /tmp/MY_PPT_FILE --outdir /tmp

Where YOUR_HOST_PATH is within my python app container

What I need to happen

I need the python app to call the libreoffice container and convert the ppt file residing in the python app container and then make the path of the converted document available for the frontend to render.

Basically how to make files in different docker containers accessible to each other using docker-compose

My docker-compose.yaml:

version: '3'
services:
  backend:
    image: interrodata_backend
    build: ./backend
    ports:
      - "9090:9090"
    depends_on:
      - db
    environment:
      - DATABASE_HOST=db
  db:
    image: nielsen_db
    restart: always
    build: ./db
Ludo
  • 2,307
  • 2
  • 27
  • 58
  • Let me conclude, you are asking two questions: 1) How two share files between different containers? 2) How to call commands in another container? Am I right? – Yuankun Apr 09 '18 at 15:42
  • Yes, that is correct. And specifically how to point to these files via their filepath – Ludo Apr 09 '18 at 16:11

1 Answers1

1

How to call commands in another container?

In this answer, @Horgix explains ways to invoke an executable resided in another container. For your case, the cleanest way is to make your libreoffice container a service, and expose an HTTP API to outside. Then call this API from the Python app container.

How to share files between different containers?

You can use either volumes or bind-mounts to achieve this.

For example, to use bind-mounts:

docker run -v /host/path:/tmp python-app
docker run -v /host/path:/tmp libreoffice-headless

The Python app generates files to its own /tmp directory. And the libreoffice app will find the same files in its own /tmp directory. They are sharing the same directory.

Same idea for using volumes. You can find more information here.

Yuankun
  • 6,875
  • 3
  • 32
  • 34
  • Ok, assuming I go with API and volumes. I will expose my libreoffice port in both the docker-compose.yaml and its docker file as I did above with the db. What about for volumes do I have to state `VOLUME ["/tmp"]` in my libreoffice dockerfile and in my compose.yaml or is it sufficient just to have it in the dockerfile? Could you also answer by providing an edited version of my docker-compose.yaml please? – Ludo Apr 10 '18 at 06:33