Я работал над проектом, разработанным с Docker на Windows. Но когда я продолжил работать над этим на моей машине Linux, я получил страницу 404 Not Found nginx.
Docker Составление журналов на моей службе веб-сервера говорит, что разрешение отклонено
webserver | 2020/03/14 10:05:29 [crit] 6#6: *1 stat() "/var/www/public/" failed (13: Permission denied), client: <my_ip_address>, server: , request: "GET / HTTP/1.1", host: "localhost"
webserver | 2020/03/14 10:05:29 [crit] 6#6: *1 stat() "/var/www/public/" failed (13: Permission denied), client: <my_ip_address>, server: , request: "GET / HTTP/1.1", host: "localhost"
webserver | 2020/03/14 10:05:29 [crit] 6#6: *1 stat() "/var/www/public/index.php" failed (13: Permission denied), client: <my_ip_address>, server: , request: "GET / HTTP/1.1", host: "localhost"
webserver | <my_ip_address> - - [14/Mar/2020:10:05:29 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0"
Я попытался запустить это в каталоге приложения на моем хост-компьютере, но проблема не исчезла:
sudo chown -R $USER:$USER ~/my-app
Вот мой docker -compose.yml:
version: '3'
#Docker Services
services:
#PHP + Laravel Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
networks:
- app-network
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
networks:
- app-network
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: <password>
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- app-network
volumes:
- dbdata:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Вот файл Docker:
FROM php:7.2-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Я попытался изменить строку 42 в Dockerfile на это, но это не помогает:
RUN chown -R www:www /var/www
Я использую:
- Linux Mint 18.3 Cinnamon (3.6.7) 64-bit
- Linux ядро 4.15.0-88-generi c
- Docker версия 19.03.8, сборка afacb8b7f0
- docker - составная версия 1.25.4, сборка 8d51620a
РЕДАКТИРОВАТЬ: дополнительная информация
$ docker-compose exec app ls -la /var/www
total 1076
drwx------ 17 www www 4096 Mar 14 11:05 .
drwxr-xr-x 1 root root 4096 Feb 26 11:59 ..
-rw-rw-r-- 1 www www 235 Mar 10 10:27 .editorconfig
-rw-rw-r-- 1 www www 983 Mar 13 10:26 .env
-rw-rw-r-- 1 www www 824 Mar 10 10:27 .env.example
drwx------ 7 www www 4096 Mar 14 11:05 .git
-rw-rw-r-- 1 www www 116 Mar 10 10:27 .gitattributes
-rw-rw-r-- 1 www www 175 Mar 10 10:27 .gitignore
-rw-rw-r-- 1 www www 187 Mar 10 10:27 .styleci.yml
-rw-rw-r-- 1 www www 34515 Mar 10 10:27 CHANGELOG.md
-rw-rw-r-- 1 www www 1206 Mar 14 11:05 Dockerfile
-rw-rw-r-- 1 www www 1597 Mar 13 20:28 README.md
drwx------ 7 www www 4096 Mar 13 17:18 app
-rw-rw-r-- 1 www www 1739 Mar 10 10:27 artisan
drwx------ 3 www www 4096 Mar 13 17:18 bootstrap
-rw-rw-r-- 1 www www 1731 Mar 13 15:08 composer.json
-rw-rw-r-- 1 www www 215207 Mar 13 15:10 composer.lock
drwx------ 2 www www 4096 Mar 13 17:18 config
drwx------ 5 www www 4096 Mar 13 17:18 database
-rw-rw-r-- 1 www www 1239 Mar 10 11:29 docker-compose.yml
drwx------ 2 www www 4096 Mar 13 17:18 mysql
drwx------ 3 www www 4096 Mar 13 17:18 nginx
drwx------ 711 www www 102400 Mar 13 17:18 node_modules
-rw-rw-r-- 1 www www 456333 Mar 10 15:43 package-lock.json
-rw-rw-r-- 1 www www 1144 Mar 10 15:43 package.json
drwx------ 2 www www 4096 Mar 13 17:18 php
-rw-rw-r-- 1 www www 1168 Mar 10 10:27 phpunit.xml
drwx------ 4 www www 4096 Mar 13 17:18 public
drwx------ 6 www www 4096 Mar 13 17:18 resources
drwx------ 2 www www 4096 Mar 13 17:18 routes
-rw-rw-r-- 1 www www 584 Mar 10 10:27 server.php
drwx------ 5 www www 4096 Mar 13 17:18 storage
drwx------ 4 www www 4096 Mar 13 17:18 tests
drwx------ 48 www www 12288 Mar 13 17:18 vendor
-rw-rw-r-- 1 www www 553 Mar 10 10:27 webpack.mix.js
failed to resize tty, using default size