V
V
vrazbros2020-05-04 16:37:16
Docker
vrazbros, 2020-05-04 16:37:16

How to work with laravel in docker?

developed a small docker compose for myself to work with laravel in a docker environment
, here is its contents

version: '3'

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    depends_on:
      - php
      - mysql
    ports:
      - "80:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - laravel

  mysql:
    image: mysql:5.7
    container_name: mysql
    tty: true
    ports:
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=laravel
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - laravel
  php:
    build: ./php
    container_name: php
    volumes:
      - ./src:/var/www/html
    ports:
      - "9000:9000"
    networks:
      - laravel


but when working, there are a number of problems with the rights to files and directories, for example
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Googled basically everyone suggests putting permissions on the folder 777, but is this a huge security hole? How can it be solved?

and the 2nd time I go into the container with php, then the current user is root, if I create migrations or a controller, then I can’t modify these files on the host machine, because the created files are created under root, what should I do in this case?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question