Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

php - Sync vendor folder from container with host folder

so what I'm trying to do is.

  1. build docker image
  2. run composer install within Dockerfile
  3. have the vendor folder with installed dependencies on my host machine aswell

What I acomplished since now is I managed to install dependencies on my container and everything runs fine. Although my vendor folder on my host machine is empty. So my IDE (phpstorm) doesn't recognize classes from installed packages (obviously) and this is the problem I need to solve.

What I tried:

  1. create a volume: it seems this copied the empty vendor folder and overwritten the vendor folder on container
  2. run composer install after starting container (this takes just too long time and it always installs all the packages again...not acceptable)

my docker-compose.yml:

services:
  web:
    build:
      context: .
      dockerfile: ./config/web/Dockerfile
    image: web
    container_name: WebServer
    ports:
      - "8081:80"
    volumes:
      - ./src:/var/www/notification
      - /var/www/notification/vendor
    networks:
      - network

and my Dockerfile:

FROM php:7.4-apache

# Install GIT
RUN apt-get update && 
    apt-get upgrade -y && 
    apt-get install -y git && 
    apt-get install -y nano && 
    apt-get install -y libzip-dev && 
    apt-get install -y zip unzip

# Install ext for PHP
RUN docker-php-ext-install pdo pdo_mysql zip


# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Enable apache2 mod_rewrite module
RUN a2enmod rewrite

WORKDIR /var/www/smthing

COPY ./src/composer.json ./src/composer.lock ./

RUN composer install

Is there a way to sync this somehow automatically, without it taking forever?

Thanks in advance everyone :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...