1

I am new to Docker trying to Dockerize simple lumen app locally.

Dockerfile:

FROM php:8.1 as php

WORKDIR /var/www

COPY ./ /project
COPY . .

COPY --from=composer:2.4.2 /usr/bin/composer /usr/bin/composer

docker-composer.yml:

version: "20.10"
services:
  # PHP Service
  php:
    build:
      context: .
      target: php
      args:
        - APP_ENV=${APP_ENV}
    environment:
      - APP_ENV=${APP_ENV}
      - CONTAINER_ROLE=app
    working_dir: /var/www
    volumes:
      - ./:/var/www
    ports:
      - 8000:8000

  # Libre Office Service
  libreoffice:
    image: lscr.io/linuxserver/libreoffice:latest
    container_name: libreoffice
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
    volumes:
      - ./:/var/www
    ports:
      - 3000:3000
    restart: unless-stopped

Everything works fine but I can't copy my project to custom directory in libreoffice container.

When I access libreoffice container with docker exec -it libreoffice /bin/bash I can't see project directory here. But in /var/www directory there is all directories that is in my local computer.

You may question why you are trying to copy your project to different directory?

Because I am running following command in libreoffice container:

docker exec libreoffice soffice --headless --invisible --convert-to pdf --outdir "var/www/PhpstormProjects/document-converter/public/tmp" "var/www/PhpstormProjects/document-converter/public/tmp/hi.docx"

But in this commannd I don't want to specify my path like var/www/PhpstormProjects/document-converter/public/tmp.

Because when I upload it to the live server the directory will change and it will not work properly. Means each time I change project path, I will need to change path in code as well.

Please let me know what I am doing wrong or another way I can do it.

4
  • /project is declared in the Dockerfile you use for the 'php' service. Has nothing to do with your local setup. Also you copy the same files twice: to /project and to /var/www in the php service. Doesn't really make sense Commented Oct 3, 2022 at 8:49
  • I know. But how can I copy my project to /project folder? In which service I have to do it? As I said I am new to docker so I need exact solution for my issue. Commented Oct 3, 2022 at 8:52
  • 1
    just add a volume ".:/project" to your libreoffice service. Commented Oct 3, 2022 at 8:58
  • Thanks. You can post an answer I will accept it. Commented Oct 3, 2022 at 9:38

1 Answer 1

0

By help of @Mihai I have found that:

COPY in the Dockerfile is related to php service as I defined at the top:

FROM php:8.1 as php

It has nothing to do with libreoffice service. To COPY my project to libreoffice service I need to define volume for it in docker-compose.yml file like:

# Libre Office Service
  libreoffice:
    image: lscr.io/linuxserver/libreoffice:latest
    container_name: libreoffice
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
    volumes:
      - ./:/project # You can define any directory you want
    ports:
      - 3000:3000
    restart: unless-stopped
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.