4

I installed magento using composer:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition

and load sample data. It works pretty fine on localhost.

I created dockerfile and docker-compose for magento: 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. May it happend because of Windows?

Do You have any ideas hot can I fix it?

0

2 Answers 2

1

Finally I solved it.

There is my Dockerfile for Apache/php:

FROM ubuntu:latest

MAINTAINER Konrad Siamro

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 php-soap

RUN apt-get -qqy install bindfs \
    dos2unix \
    php-xdebug

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

COPY ./20-mcrypt.ini /etc/php/7.0/cli/conf.d/20-mcrypt.ini
COPY ./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/xdebug.ini
COPY ./auth.json /var/www/auth.json

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

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

RUN a2enmod php7.0

RUN echo "extension=php_openssl.dll" >> /etc/php/7.0/apache2/php.ini

RUN service apache2 restart

WORKDIR /var/www/html

COPY ./ssh /var/ssh

EXPOSE 9001
EXPOSE 80
EXPOSE 443

COPY ./start_safe_perms.sh /usr/local/bin/start_safe_perms.sh
RUN dos2unix /usr/local/bin/start_safe_perms.sh
RUN chmod 777 /usr/local/bin/start_safe_perms.sh
CMD ["/bin/bash", "/usr/local/bin/start_safe_perms.sh"]

and apache2 conf:

# this is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#   /etc/apache2/
#   |-- apache2.conf
#   |   `--  ports.conf
#   |-- mods-enabled
#   |   |-- *.load
#   |   `-- *.conf
#   |-- conf-enabled
#   |   `-- *.conf
#   `-- sites-enabled
#       `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

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

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

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

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


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<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>

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>



# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
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

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Sign up to request clarification or add additional context in comments.

Comments

0

This is my Dockerfile support PHP-FMP:

FROM php:7.4.20-fpm

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

# Locales
RUN apt-get update \
    && apt-get install -y locales

RUN dpkg-reconfigure locales \
    && locale-gen C.UTF-8 \
    && /usr/sbin/update-locale LANG=C.UTF-8

RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen \
    && locale-gen

ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

# Common
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        openssl \
        git \
        gnupg2 \
        vim \
        telnet \
        cron

# Install php extension

# intl
RUN apt-get install -y libicu-dev \
    && docker-php-ext-configure intl \
    && docker-php-ext-install -j$(nproc) intl

# xml
RUN apt-get install -y \
    libxml2-dev \
    libxslt-dev \
    && docker-php-ext-install -j$(nproc) \
        dom \
        xmlrpc \
        xsl \
        simplexml

# images
RUN apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libgd-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) \
        gd \
        exif

# database
RUN docker-php-ext-install -j$(nproc) \
    mysqli \
    pdo \
    pdo_mysql

# strings
RUN apt-get install -y libonig-dev \
    && docker-php-ext-install -j$(nproc) \
    gettext \
    mbstring

# math
RUN apt-get install -y libgmp-dev \
    && ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h \
    && docker-php-ext-install -j$(nproc) \
        gmp \
        bcmath

# compression
RUN apt-get install -y \
    libbz2-dev \
    zlib1g-dev \
    libzip-dev \
    && docker-php-ext-install -j$(nproc) \
        zip \
        bz2

# memcached
RUN apt-get install -y \
    libmemcached-dev \
    libmemcached11

# curl
RUN apt-get install -y \
    libcurl4 \
    libcurl4-openssl-dev \
    && docker-php-ext-install -j$(nproc) curl

# images
RUN apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libgd-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) \
        gd \
        exif

# others
RUN docker-php-ext-install -j$(nproc) \
    soap \
    sockets \
    calendar \
    sysvmsg \
    sysvsem \
    sysvshm \
    ctype \
    iconv

# Install form source

# ext-apcu
ENV EXT_APCU_VERSION=5.1.17

RUN mkdir -p /usr/src/php/ext/apcu \
    && curl -fsSL https://github.com/krakjoe/apcu/archive/v$EXT_APCU_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/apcu --strip 1 \
    && docker-php-ext-install apcu \
    && echo "[apcu]" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini \
    && echo "apc.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

# ext-opache
RUN docker-php-source extract \
    && docker-php-ext-enable opcache \
    && echo "zend_extension=opcache" >> /tmp/docker-php-ext-opcache.ini \
    && echo "opcache.enable=1" >> /tmp/docker-php-ext-opcache.ini \
    && echo "opcache.enable_cli=0" >> /tmp/docker-php-ext-opcache.ini \
    && echo "opcache.memory_consumption=356" >> /tmp/docker-php-ext-opcache.ini \
    && echo "opcache.max_accelerated_files=100000" >> /tmp/docker-php-ext-opcache.ini \
    && echo "opcache.validate_timestamps=0" >> /tmp/docker-php-ext-opcache.ini

# x-debug
RUN pecl install xdebug-3.0.4 \
    && docker-php-ext-enable xdebug \
    && echo "zend_extension=xdebug" >> /tmp/docker-php-ext-xdebug.ini \
    && echo "xdebug.mode=debug,develop" >> /tmp/docker-php-ext-xdebug.ini \
    && echo "xdebug.start_with_request=yes" >> /tmp/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_port=9003" >> /tmp/docker-php-ext-xdebug.ini \
    && echo "xdebug.discover_client_host=true" >> /tmp/docker-php-ext-xdebug.ini \
    && echo "xdebug.client_host=host.docker.internal" >> /tmp/docker-php-ext-xdebug.ini

# clean up
RUN docker-php-source delete

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN cd /usr/local/etc/php/conf.d/ && \
    echo 'memory_limit = 2G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini

# Add user
RUN groupadd -g 1000 app \
    && useradd -g 1000 -u 1000 -d /var/www -s /bin/bash app

RUN mkdir -p /var/www/html \
    && chown -R app:app /var/www

USER app:app
VOLUME /var/www
WORKDIR /var/www/html

So It's my repository, check it out!

https://github.com/dylanops/docker-magento

1 Comment

Hey, it is a quite old topic :) but thanks for Your solution. Right now I am working with DDEV instead of Docker directly. I can definitely recommend that solution for You too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.