Coder Social home page Coder Social logo

Why we need to run composer install inside the docker file, if it will be overwritten with volumes. about docker-nginx-php-laravel HOT 11 CLOSED

systemsdk avatar systemsdk commented on June 29, 2024
Why we need to run composer install inside the docker file, if it will be overwritten with volumes.

from docker-nginx-php-laravel.

Comments (11)

dimadeush avatar dimadeush commented on June 29, 2024

Hello
Please pay attention to the other docker-compose files that you have inside this repo and there you don't have mapping at all. That's why for all environments except dev you need to copy files inside.

Please inform us if you need anything else

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

Hi,
I see that in docker-compose for staging and prod there are no volumes in the laravel section, but there are volumes in nginx, still, this will copy the local files into nginx container, not the laravel container, for example, if we don't have the vendor file locally, this will means there is no vendor file in the nginx container because there is no connection between the nginx container and the larevel container, so what I did is create new volume in both nginx and laravel:

NGINX :
volumes:

  • php:/var/www/html

LARAVEL:
volumes:

  • php:/var/www/html

and at the bottom:
volumes:
php:
driver: local

I'm still confuse how we can share file between nginx and laravel

from docker-nginx-php-laravel.

dimadeush avatar dimadeush commented on June 29, 2024

Hi
We have public folder inside NGINX and it is enough for proxy, and basically, NGINX just as "proxy". Please execute necessary commands in order to build prod/staging environments and check that everything are working as expected.

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

I know, ok, could you please explain this to me

    set $root /var/www/html/public;

    root $root;

in the nginx config, my question is how nginx proxy to the folder that exists in the larevel container, maybe the line above explains that?

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

and what the purpose for this line in the docker-composer nginx:

      volumes:
        - .:/var/www/html:ro,cached

from docker-nginx-php-laravel.

dimadeush avatar dimadeush commented on June 29, 2024

Please pay attention to the line https://github.com/systemsdk/docker-nginx-php-laravel/blob/master/docker/dev/nginx.conf#L59

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

my question is how nginx proxy to the file that exists in the laravel container.

DEV:
image

PROD/STAGE:
image

I'm quite not sure how nginx container proxy to the files that exist in the laravel container(I think it does not do that), nginx proxy to the files that bean copies locally.(so if we dont have a vendor locally it will not work), therefore why do we need to copy files and run composer install inside the dockerfile for laravel?

what I did to make it work:
image

so now copying the local files and running composer install affects both containers, without the need to run composer install locally and then run composer install after the containers have been built

docker-compose.yaml

version: '3'
services:
    ### NGINX Server #########################################
    nginx:
        build:
            context: "./docker/nginx"
        depends_on:
            -   php-fpm
        volumes:
            - ${NGINX_SSL_PATH}:/etc/nginx/ssl
            - ${NGINX_HOST_LOG_PATH}:/var/log/nginx
            - php:/var/www/html
            # - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}

        ports:
            # port mappings, host to docker
            - "${NGINX_HOST_HTTPS_PORT}:443"
            - "${NGINX_HOST_HTTP_PORT}:80"
        networks:
            - backend
        container_name: ${COMPOSE_PROJECT_NAME}-nginx

    ### PHP-FPM ##############################################
    php-fpm:
        build:
            context: .
        volumes:
            - php:/var/www/html
        depends_on:
            - redis
            # - mariadb
        networks:
            - backend
        expose:
            - "9000"
        container_name: ${COMPOSE_PROJECT_NAME}-php-fpm
networks:
    backend:
        driver: bridge
volumes:
    redis:
        driver: local
    php:
        driver: local

from docker-nginx-php-laravel.

dimadeush avatar dimadeush commented on June 29, 2024

Basically if you want to check your theory you can make next steps:
1)delete vendor folder locally
2)create some App\Http\Controllers\TestController with method show that "return view('welcome');"
3)edit routes/web.php and put there "Route::get('/test', [TestController::class, 'show']);"
2)make build-prod
3)make start-prod
4)make key-generate
5)enter make ssh-nginx and make sure that you don't have vendor folder there
6)enter make ssh and make sure that you have vendor folder inside
7)open your browser and access http://localhost/test and it should be available

So, basically, if you want to have vendor folder inside NGINX you can use your example above but you don't need vendor folder there as there is no php interpreter inside NGINX at all. Maybe you need to pay attention to the NGINX config and understand how it is working.

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

my problem is how can nginx container proxy to a file/folder that does not exist in the image, I don't know how nginx proxy to the folder that exists inside another image.

ps:
why do we do this there is no point right(in ngixn docker-compose file):
volumes:
- .:/var/www/html:ro,cached

from docker-nginx-php-laravel.

dimadeush avatar dimadeush commented on June 29, 2024

You can read NGINX manual and examples if you want to understand config properly.

ps:
Currently what you need is to have just everything that are inside public folder as you have default nginx config set $root /var/www/html/public; so you can map as - ./public:/var/www/html/public:ro,cached (and NGINX will check if index.php file exists and transfer request to the laravel image).

But if you want to use environment not only for api requests, maybe you will need to change NGINX config and allow to access some other folders(static html files or images, etc...), that's why currently we have everything except vendor.

from docker-nginx-php-laravel.

Mahmoud-Skafi avatar Mahmoud-Skafi commented on June 29, 2024

@dimadeush thanks so much, everything is now clear to me.

from docker-nginx-php-laravel.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.