Docker Community Forums

Share and learn in the Docker community.

Magento2 - problem with permisions Windows 10

build
docker

(Lolasek) #1

Hello,

I created docker for Magento2.
It mostly works fine but some .css cant be loaded.
I’m pretty sure it may be because of permissions.
However I will show You config first.

I’m on Windows 10.

$ docker version
Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 23:26:11 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 23:26:11 2016
 OS/Arch:      linux/amd64

Dockerfile:

FROM ubuntu:latest

MAINTAINER xxxx

RUN apt-get -qqy update

RUN apt-get -qqy install apache2 \
        php \
        mysql-client \
        libapache2-mod-php \
        php-pear \
        php-mcrypt \
        php-gd \
        php-curl \
        php-mysql \
        php-dom \
        php-xml \
        php-xsl \
        php-mbstring \
        php-intl \
        php-zip \
        php-cli \
        php-cgi \
        curl \
        git \
        nano \
        vim \
        htop
RUN apt-get -qqy install nodejs npm
RUN apt-get -qqy install php-fpm

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

ADD ./20-mcrypt.ini /etc/php/7.0/cli/conf.d/20-mcrypt.ini
ADD ./20-mcrypt.ini /etc/php/7.0/apache2/conf.d/20-mcrypt.ini


RUN a2enmod rewrite

COPY ./magento2.conf /etc/apache2/sites-available/magento2.conf
#RUN rm -f /etc/apache2/sites-enabled/000-default.conf

#COPY xdebug-enabler.ini /etc/php/7.0/mods-available/

RUN php -r "echo ini_get('memory_limit').PHP_EOL;"

COPY ./apache2.conf /etc/apache2/apache2.conf

RUN a2enmod php7.0
RUN service apache2 restart


WORKDIR /var/www/html

EXPOSE 9001
EXPOSE 80
EXPOSE 443

magento2.conf:

<VirtualHost *:80>
       DocumentRoot /var/www/html
       ServerName magento2test.localhost
       <Directory /var/www/html>
        DirectoryIndex index.php index.html
            Options Indexes FollowSymLinks
            AllowOverride All
            Order allow,deny
            allow from all
       </Directory>
</VirtualHost>

apache2.conf:

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


User ${APACHE_RUN_USER}
HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
    Options +Indexes +FollowSymLinks +Multiviews
	allowOverride  all
	Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

AccessFileName .htaccess

<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>


LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

and finaly docker-compose:

mageweb:
  build: docker-files/apache-xdebug
  command: rm -f /var/run/apache2/apache2.pid
  command: apachectl -D FOREGROUND
  ports:
    - "8081:8081"
    - "80:80"
    - "9001:9001"
    - "443:443"
  volumes:
    -  ./project/:/var/www/html/

Now it is only one image cause im using remote mysql and I will add more images later.

Anyway I’m able to build and up docker.
I’m able to install and setup magento.
Of course I tried flush all cache, and done all of those comands (using docker exec -it container_name bash:

php  bin/magento setup:static-content:deploy
php bin/magento indexer:reindex
php bin/magento setup:upgrade --keep-generated
php bin/magento module:enable --all
php bin/magento setup:di:compile

But style.css and some js are not loading property:
https://postimg.org/image/wla49rvrz/

system.log:

[2016-11-17 07:27:39] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_2ae0e2a835d549823c9720ea0833000d3 and handles default, catalog_category_view, catalog_category_view_type_default, catalog_category_view_type_default_without_children, catalog_category_view_id_39: Please correct the XML data and try again.  [] []
[2016-11-17 07:27:39] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_2a7ccd8094436548b564a588f6303121c and handles 2columns-left: Please correct the XML data and try again.  [] []
[2016-11-17 07:27:40] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_26f1b068ec7ccf4878f9284dd1137afd1 and handles catalog_product_prices: Please correct the XML data and try again.  [] []

When Im trying change permissions for project on docker container it won’t apply.
Trying by login into container docker exec -it xxx bash

Then I would like to add permision file to end of dockerfile:

COPY ./start_safe_perms.sh /usr/local/bin/
RUN chmod 777 /usr/local/bin/start_safe_perms.sh
ENTRYPOINT ["/usr/local/bin/start_safe_perms.sh"]

and start_safe_perms.sh:

#!/bin/bash
cd /var/www/html
chmod -R u+w .
find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
chmod o+rwx app/etc/env.php
rm -f /var/run/apache2/apache2.pid
apachectl -D FOREGROUND

Ofc i removed comands on docker-compose:

mageweb:
  build: docker-files/apache-xdebug
  ports:
    - "8081:8081"
    - "80:80"
    - "9001:9001"
    - "443:443"
  volumes:
    -  ./project/:/var/www/html/

Right now when I am starting container:

$ docker-compose up
Recreating magento2test_mageweb_1
Attaching to magento2test_mageweb_1
mageweb_1  | panic: standard_init_linux.go:175: exec user process caused "permission denied" [recovered]
mageweb_1  |    panic: standard_init_linux.go:175: exec user process caused "permission denied"
mageweb_1  |
mageweb_1  | goroutine 1 [running, locked to thread]:
mageweb_1  | panic(0x88f8a0, 0xc820139dc0)
mageweb_1  |    /usr/local/go/src/runtime/panic.go:481 +0x3e6
mageweb_1  | github.com/urfave/cli.HandleAction.func1(0xc8201092e8)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/urfave/cli/app.go:478 +0x38e
mageweb_1  | panic(0x88f8a0, 0xc820139dc0)
mageweb_1  |    /usr/local/go/src/runtime/panic.go:443 +0x4e9
mageweb_1  | github.com/opencontainers/runc/libcontainer.(*LinuxFactory).StartInitialization.func1(0xc820108bf8, 0xc82001a0b8, 0xc820108d08)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/factory_linux.go:259 +0x136
mageweb_1  | github.com/opencontainers/runc/libcontainer.(*LinuxFactory).StartInitialization(0xc820058960, 0x7f55cea274b8, 0xc820139dc0)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/factory_linux.go:277 +0x5b1
mageweb_1  | main.glob.func8(0xc820076780, 0x0, 0x0)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/main_unix.go:26 +0x68
mageweb_1  | reflect.Value.call(0x7f45a0, 0x9a4d88, 0x13, 0x8ebac8, 0x4, 0xc820109268, 0x1, 0x1, 0x0, 0x0, ...)
mageweb_1  |    /usr/local/go/src/reflect/value.go:435 +0x120d
mageweb_1  | reflect.Value.Call(0x7f45a0, 0x9a4d88, 0x13, 0xc820109268, 0x1, 0x1, 0x0, 0x0, 0x0)
mageweb_1  |    /usr/local/go/src/reflect/value.go:303 +0xb1
mageweb_1  | github.com/urfave/cli.HandleAction(0x7f45a0, 0x9a4d88, 0xc820076780, 0x0, 0x0)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/urfave/cli/app.go:487 +0x2ee
mageweb_1  | github.com/urfave/cli.Command.Run(0x8ee970, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x984240, 0x51, 0x0, ...)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/urfave/cli/command.go:191 +0xfec
mageweb_1  | github.com/urfave/cli.(*App).Run(0xc820001680, 0xc82000a100, 0x2, 0x2, 0x0, 0x0)
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/Godeps/_workspace/src/github.com/urfave/cli/app.go:240 +0xaa4
mageweb_1  | main.main()
mageweb_1  |    /tmp/tmp.n151sEscRu/src/github.com/opencontainers/runc/main.go:137 +0xe24
magento2test_mageweb_1 exited with code 2

Do You have an any idea how to resolve it?