GithubHelp home page GithubHelp logo

markshust / docker-magento Goto Github PK

View Code? Open in Web Editor NEW
2.4K 72.0 959.0 1.37 MB

Mark Shust's Docker Configuration for Magento

Home Page: https://m.academy/courses/set-up-magento-2-development-environment-docker/

License: MIT License

Shell 69.53% Dockerfile 18.40% Makefile 12.06%
magento magento2 magento-2 docker-magento docker docker-compose hacktoberfest

docker-magento's Introduction

markshust/docker-magento

Mark Shust's Docker Configuration for Magento

Supported Magento Versions Docker Hub Pulls - PHP Docker Hub Pulls - Nginx Maintained - Yes Apple Silicon Support

Table of contents

Docker Hub

View Dockerfiles for the latest tags:

Free Course

This course is sponsored by M.academy, the simplest way to learn Magento.

M.academy

A free screencast course is available (which was fully refreshed in December 2021), which details the basic usage of this project:

Set Up a Magento 2 Development Environment with Docker
Set Up a Magento 2 Development Environment with Docker

Course Curriculum

Intro

Initial Project Setup

The Basics of docker-magento

Docker Filesystem & Data Volumes

PhpStorm

Code Quality Tools

Xdebug

Customize Server Configurations

Usage

This configuration is intended to be used as a Docker-based development environment for Magento 2.

Folders:

  • images: Docker images for nginx and php
  • compose: sample setups with Docker Compose

The Magento 1 version of this development environment has been deprecated and is no longer supported. PHP 5 was used as it's base, and that version has reached end-of-life. If you still wish to use this setup, please reference compose/magento-1 on tag 20.1.1, but please be aware these images are no longer maintained.

Prerequisites

This setup assumes you are running Docker on a computer with at least 6GB of RAM allocated to Docker, a dual-core, and an SSD hard drive. Download & Install Docker Desktop.

This configuration has been tested on Mac & Linux. Windows is supported through the use of Docker on WSL.

Setup

Automated Setup (New Project)

# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_

# Run this automated one-liner from the directory you want to install your project.
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento.test 2.4.7 community

The magento.test above defines the hostname to use, and the 2.4.7 defines the Magento version to install. Note that since we need a write to /etc/hosts for DNS resolution, you will be prompted for your system password during setup.

After the one-liner above completes running, you should be able to access your site at https://magento.test.

Install sample data

After the above installation is complete, run the following lines to install sample data:

bin/magento sampledata:deploy
bin/magento setup:upgrade

Manual Setup

Same result as the one-liner above. Just replace magento.test references with the hostname that you wish to use.

New Projects

# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_

# Download the Docker Compose template:
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash

# Download the version of Magento you want to use with:
bin/download 2.4.7 community
# You can specify the version and type (community, enterprise, mageos, mageos-nightly, mageos-mirror, mageos-hypernode-mirror, or mageos-maxcluster-mirror).
# The mageos type is an alias for mageos-mirror.
# If no arguments are passed, "2.4.7" and "community" are the default values used.

# or for Magento core development:
# bin/start --no-dev
# bin/setup-composer-auth
# bin/cli git clone [email protected]:magento/magento2.git .
# bin/cli git checkout 2.4-develop
# bin/composer install

# Want to install Magento <2.4.6? In bin/setup-install, replace the lines:
#  --elasticsearch-host="$ES_HOST" \
#  --elasticsearch-port="$ES_PORT" \
#  --opensearch-host="$OPENSEARCH_HOST" \
#  --opensearch-port="$OPENSEARCH_PORT" \
#  --search-engine=opensearch \
# with:
#  --elasticsearch-host="$ES_HOST" \
#  --elasticsearch-port="$ES_PORT" \
#  --search-engine=elasticsearch7 \

# Run the setup installer for Magento:
bin/setup magento.test

open https://magento.test

Existing Projects

# Create your project directory then go into it:
mkdir -p ~/Sites/magento
cd $_

# Download the Docker Compose template:
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash

# Take a backup of your existing database:
bin/mysqldump > ~/Sites/existing/magento.sql

# Replace with existing source code of your existing Magento instance:
cp -R ~/Sites/existing src
# or: git clone [email protected]:myrepo.git src

# Start some containers, copy files to them and then restart the containers:
bin/start --no-dev
bin/copytocontainer --all ## Initial copy will take a few minutes...

# If your vendor directory was empty, populate it with:
bin/composer install

# Import existing database:
bin/mysql < ../existing/magento.sql

# Update database connection details to use the above Docker MySQL credentials:
# Also note: creds for the MySQL server are defined at startup from env/db.env
# vi src/app/etc/env.php

# Import app-specific environment settings:
bin/magento app:config:import

# Create a DNS host entry and setup Magento base url
bin/setup-domain yoursite.test

bin/restart

open https://magento.test

Elasticsearch vs OpenSearch

OpenSearch is set as the default search engine when setting up this project. Follow the instructions below if you want to use Elasticsearch instead:

  1. Comment out or remove the opensearch container in both the compose.yaml and compose.healthcheck.yaml files
  2. Uncomment the elasticsearch container in both the compose.yaml and compose.healthcheck.yaml files
  3. Update the bin/setup-install command to use the Elasticsearch ratther than OpenSearch. Change:
--opensearch-host="$OPENSEARCH_HOST" \
--opensearch-port="$OPENSEARCH_PORT" \

to:

--elasticsearch-host="$ES_HOST" \
--elasticsearch-port="$ES_PORT" \

Updates

To update your project to the latest version of docker-magento, run:

bin/update

We recommend keeping your docker config files in version control, so you can monitor the changes to files after updates. After reviewing the code updates and ensuring they updated as intended, run bin/restart to restart your containers to have the new configuration take effect.

It is recommended to keep your root docker config files in one repository, and your Magento code setup in another. This ensures the Magento base path lives at the top of one specific repository, which makes automated build pipelines and deployments easy to manage, and maintains compatibility with projects such as Magento Cloud.

Custom CLI Commands

  • bin/analyse: Run phpstan analyse within the container to statically analyse code, passing in directory to analyse. Ex. bin/analyse app/code
  • bin/bash: Drop into the bash prompt of your Docker container. The phpfpm container should be mainly used to access the filesystem within Docker.
  • bin/blackfire: Disable or enable Blackfire. Accepts argument disable, enable, or status. Ex. bin/blackfire enable
  • bin/cache-clean: Access the cache-clean CLI. Note the watcher is automatically started at startup in bin/start. Ex. bin/cache-clean config full_page
  • bin/check-dependencies: Provides helpful recommendations for dependencies tailored to the chosen Magento version.
  • bin/cli: Run any CLI command without going into the bash prompt. Ex. bin/cli ls
  • bin/clinotty: Run any CLI command with no TTY. Ex. bin/clinotty chmod u+x bin/magento
  • bin/cliq: The same as bin/cli, but pipes all output to /dev/null. Useful for a quiet CLI, or implementing long-running processes.
  • bin/composer: Run the composer binary. Ex. bin/composer install
  • bin/configure-linux: Adds the Docker container's IP address to the system's /etc/hosts file if it's not already present. Additionally, it prompts the user to open port 9003 for Xdebug if desired.
  • bin/copyfromcontainer: Copy folders or files from container to host. Ex. bin/copyfromcontainer vendor
  • bin/copytocontainer: Copy folders or files from host to container. Ex. bin/copytocontainer --all
  • bin/create-user: Create either an admin user or customer account.
  • bin/cron: Start or stop the cron service. Ex. bin/cron start
  • bin/debug-cli: Enable Xdebug for bin/magento, with an optional argument of the IDE key. Defaults to PHPSTORM Ex. bin/debug-cli enable PHPSTORM
  • bin/deploy: Runs the standard Magento deployment process commands. Pass extra locales besides en_US via an optional argument. Ex. bin/deploy nl_NL
  • bin/dev-test-run: Facilitates running PHPUnit tests for a specified test type (e.g., integration). It expects the test type as the first argument and passes any additional arguments to PHPUnit, allowing for customization of test runs. If no test type is provided, it prompts the user to specify one before exiting.
  • bin/dev-urn-catalog-generate: Generate URN's for PhpStorm and remap paths to local host. Restart PhpStorm after running this command.
  • bin/devconsole: Alias for bin/n98-magerun2 dev:console
  • bin/docker-compose: Support V1 (docker-compose) and V2 (docker compose) docker compose command, and use custom configuration files, such as compose.yml and compose.dev.yml
  • bin/docker-stats: Display container name and container ID, status for CPU, memory usage(in MiB and %), and memory limit of currently-running Docker containers.
  • bin/download: Download specific Magento version from Composer to the container, with optional arguments of the version (2.4.7 [default]) and type ("community" [default], "enterprise", or "mageos"). Ex. bin/download 2.4.7 enterprise
  • bin/fixowns: This will fix filesystem ownerships within the container.
  • bin/fixperms: This will fix filesystem permissions within the container.
  • bin/grunt: Run the grunt binary. Ex. bin/grunt exec
  • bin/install-php-extensions: Install PHP extension in the container. Ex. bin/install-php-extensions sourceguardian
  • bin/log: Monitor the Magento log files. Pass no params to tail all files. Ex. bin/log debug.log
  • bin/magento: Run the Magento CLI. Ex: bin/magento cache:flush
  • bin/magento-version: Determine the Magento version installed in the current environment.
  • bin/mftf: Run the Magento MFTF. Ex: bin/mftf build:project
  • bin/mysql: Run the MySQL CLI with database config from env/db.env. Ex. bin/mysql -e "EXPLAIN core_config_data" orbin/mysql < magento.sql
  • bin/mysqldump: Backup the Magento database. Ex. bin/mysqldump > magento.sql
  • bin/n98-magerun2: Access the n98-magerun2 CLI. Ex: bin/n98-magerun2 dev:console
  • bin/node: Run the node binary. Ex. bin/node --version
  • bin/npm: Run the npm binary. Ex. bin/npm install
  • bin/phpcbf: Auto-fix PHP_CodeSniffer errors with Magento2 options. Ex. bin/phpcbf <path-to-extension>
  • bin/phpcs: Run PHP_CodeSniffer with Magento2 options. Ex. bin/phpcs <path-to-extension>
  • bin/phpcs-json-report: Run PHP_CodeSniffer with Magento2 options and save to report.json file. Ex. bin/phpcs-json-report <path-to-extension>
  • bin/pwa-studio: (BETA) Start the PWA Studio server. Note that Chrome will throw SSL cert errors and not allow you to view the site, but Firefox will.
  • bin/redis: Run a command from the redis container. Ex. bin/redis redis-cli monitor
  • bin/remove: Remove all containers.
  • bin/removeall: Remove all containers, networks, volumes, and images, calling bin/stopall before doing so.
  • bin/removenetwork: Remove a network associated with the current directory's name.
  • bin/removevolumes: Remove all volumes.
  • bin/restart: Stop and then start all containers.
  • bin/root: Run any CLI command as root without going into the bash prompt. Ex bin/root apt-get install nano
  • bin/rootnotty: Run any CLI command as root with no TTY. Ex bin/rootnotty chown -R app:app /var/www/html
  • bin/setup: Run the Magento setup process to install Magento from the source code, with optional domain name. Defaults to magento.test. Ex. bin/setup magento.test
  • bin/setup-composer-auth: Setup authentication credentials for Composer.
  • bin/setup-domain: Setup Magento domain name. Ex: bin/setup-domain magento.test
  • bin/setup-grunt: Install and configure Grunt JavaScript task runner to compile .less files
  • bin/setup-install: Automates the installation process for a Magento instance.
  • bin/setup-integration-tests: Script to set up integration tests.
  • bin/setup-pwa-studio: (BETA) Install PWA Studio (requires NodeJS and Yarn to be installed on the host machine). Pass in your base site domain, otherwise the default master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud will be used. Ex: bin/setup-pwa-studio magento.test.
  • bin/setup-pwa-studio-sampledata: This script makes it easier to install Venia sample data. Pass in your base site domain, otherwise the default master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud will be used. Ex: bin/setup-pwa-studio-sampledata magento.test.
  • bin/setup-ssl: Generate an SSL certificate for one or more domains. Ex. bin/setup-ssl magento.test foo.test
  • bin/setup-ssl-ca: Generate a certificate authority and copy it to the host.
  • bin/spx: Disable or enable output compression to enable or disbale SPX. Accepts params disable (default) or enable. Ex. bin/spx enable
  • bin/start: Start all containers, good practice to use this instead of docker-compose up -d, as it may contain additional helpers.
  • bin/status: Check the container status.
  • bin/stop: Stop all project containers.
  • bin/stopall: Stop all docker running containers
  • bin/update: Update your project to the most recent version of docker-magento.
  • bin/xdebug: Disable or enable Xdebug. Accepts argument disable, enable, or status. Ex. bin/xdebug enable

Misc Info

Install fails because project directory is not empty

The most common issue with a failed docker-magento install is getting this error:

Project directory "/var/www/html/." is not empty error

This message occurs when something fails to execute correctly during an install, and a subsequent install is re-attempted. Unfortunately, when attempting a second (or third) install, it's possible the src directory is no longer empty. This prevents Composer from creating the new project because it needs to create new projects within an empty directory.

The workaround to this is that once you have fixed the issue that was initially preventing your install from completing, you will need to completely remove the assets from the previously attempted install before attempting a subsequent install.

You can do this by running:

bin/removeall
cd ..
rm -rf yourproject

Then, create your new project directory again so you can attempt the install process again. The bin/removeall command removes all previous Docker containers & volumes related to the specific project directory you are within. You can then attempt the install process again.

Caching

For an improved developer experience, caches are automatically refreshed when related files are updated, courtesy of cache-clean. This means you can keep all of the standard Magento caches enabled, and this script will only clear the specific caches needed, and only when necessary.

To disable this functionality, uncomment the last line in the bin/start file to disable the watcher.

Database

The hostname of each service is the name of the service within the compose.yaml file. So for example, MySQL's hostname is db (not localhost) when accessing it from within a Docker container. Elasticsearch's hostname is elasticsearch.

To connect to the MySQL CLI tool of the Docker instance, run:

bin/mysql

You can use the bin/mysql script to import a database, for example a file stored in your local host directory at magento.sql:

bin/mysql < magento.sql

You also can use bin/mysqldump to export the database. The file will appear in your local host directory at magento.sql:

bin/mysqldump > magento.sql

Getting an "Access denied, you need (at least one of) the SUPER privilege(s) for this operation." message when running one of the above lines? Try running it as root with:

bin/clinotty mysql -hdb -uroot -pmagento magento < src/backup.sql

You can also remove the DEFINER lines from the MySQL backup file with:

sed 's/\sDEFINER=`[^`]*`@`[^`]*`//g' -i src/backup.sql

Composer Authentication

First setup Magento Marketplace authentication (details in the DevDocs).

Copy src/auth.json.sample to src/auth.json. Then, update the username and password values with your Magento public and private keys, respectively. Finally, copy the file to the container by running bin/copytocontainer auth.json.

Email / Mailcatcher

View emails sent locally through Mailcatcher by visiting http://{yourdomain}:1080. During development, it's easiest to test emails using a third-party module such as Mageplaza's SMTP module. In order to use mailcatcher, set the mailserver host to mailcatcher and set port to 1025. Note that this port is different from the mailcatcher interface to read the emails.

Redis

Redis is now the default cache and session storage engine, and is automatically configured & enabled when running bin/setup on new installs.

Use the following lines to enable Redis on existing installs:

Enable for Cache:

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=0

Enable for Full Page Cache:

bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=1

Enable for Session:

bin/magento setup:config:set --session-save=redis --session-save-redis-host=redis --session-save-redis-log-level=4 --session-save-redis-db=2

You may also monitor Redis by running: bin/redis redis-cli monitor

For more information about Redis usage with Magento, see the DevDocs.

PhpMyAdmin

PhpMyAdmin is built into the compose.dev.yaml file. Simply open http://localhost:8080 in a web browser.

Xdebug & VS Code

Install and enable the PHP Debug extension from the Visual Studio Marketplace.

Otherwise, this project now automatically sets up Xdebug support with VS Code. If you wish to set this up manually, please see the .vscode/launch.json file.

Xdebug & VS Code in a WSL2 environment

Install and enable the PHP Debug extension from the Visual Studio Marketplace.

Otherwise, this project now automatically sets up Xdebug support with VS Code. If you wish to set this up manually, please see the .vscode/launch.json file.

  1. In VS Code, make sure that it's running in a WSL window, rather than in the default window.
  2. Install the PHP Debug extension on VS Code.
  3. Create a new configuration file inside the project. Go to the Run and Debug section in VS Code, then click on create a launch.json file.
  4. Attention to the following configs inside the file:
    • The port must be the same as the port on the xdebug.ini file.
      bin/cli cat /usr/local/etc/php/php.ini
      memory_limit = 4G
      max_execution_time = 1800
      zlib.output_compression = On
      cgi.fix_pathinfo = 0
      date.timezone = UTC
    
      xdebug.mode = debug
      xdebug.client_host = host.docker.internal
      xdebug.idekey = PHPSTORM
      xdebug.client_port=9003
      #You can uncomment the following line to force the debug with each request
      #xdebug.start_with_request=yes
    
      upload_max_filesize = 100M
      post_max_size = 100M
      max_input_vars = 10000
    • The pathMappings should have the same folder path as the project inside the Docker container.
      {
          "version": "0.2.0",
          "configurations": [
              {
                  "name": "Listen for XDebug",
                  "type": "php",
                  "request": "launch",
                  "port": 9003,
                  "pathMappings": {
                      "/var/www/html": "${workspaceFolder}"
                  },
                  "hostname": "localhost"
              }
          ]
      }
  5. Run the following command in the Windows Powershell. It allows WSL through the firewall, otherwise breakpoints might not be hitten.
    New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

Xdebug & PhpStorm

  1. First, install the Chrome Xdebug helper. After installed, right click on the Chrome icon for it and go to Options. Under IDE Key, select PhpStorm from the list to set the IDE Key to "PHPSTORM", then click Save.

  2. Next, enable Xdebug debugging in the PHP container by running: bin/xdebug enable.

  3. Then, open PhpStorm > Preferences > PHP and configure:

    • CLI Interpreter

      • Create a new interpreter from the From Docker, Vagrant, VM... list.
      • Select the Docker Compose option.
      • For Server, select Docker. If you don't have Docker set up as a server, create one and name it Docker.
      • For Configuration files, add both the compose.yaml and compose.dev.yaml files from your project directory.
      • For Service, select phpfpm, then click OK.
      • Name this CLI Interpreter phpfpm, then click OK again.
    • Path mappings

      • There is no need to define a path mapping in this area.
  4. Open PhpStorm > Preferences > PHP > Debug and ensure Debug Port is set to 9000,9003.

  5. Open PhpStorm > Preferences > PHP > Servers and create a new server:

    • For the Name, set this to the value of your domain name (ex. magento.test).
    • For the Host, set this to the value of your domain name (ex. magento.test).
    • Keep port set to 80.
    • Check the "Use path mappings" box and map src to the absolute path of /var/www/html.
  6. Go to Run > Edit Configurations and create a new PHP Remote Debug configuration.

    • Set the Name to the name of your domain (ex. magento.test).
    • Check the Filter debug connection by IDE key checkbox, select the Server you just setup.
    • For IDE key, enter PHPSTORM. This value should match the IDE Key value set by the Chrome Xdebug Helper.
    • Click OK to finish setting up the remote debugger in PHPStorm.
  7. Open up pub/index.php and set a breakpoint near the end of the file.

    • Start the debugger with Run > Debug 'magento.test', then open up a web browser.
    • Ensure the Chrome Xdebug helper is enabled by clicking on it and selecting Debug. The icon should turn bright green.
    • Navigate to your Magento store URL, and Xdebug should now trigger the debugger within PhpStorm at the toggled breakpoint.

SSH

Since version 40.0.0, this project supports connecting to Docker with SSH/SFTP. This means that if you solely use either PhpStorm or VSCode, you no longer need to selectively mount host volumes in order to gain bi-directional sync capabilities from host to container. This will enable full speed in the native filesystem, as all files will be stored directly in the appdata container volume, rather than being synced from the host. This is especially useful if you'd like to sync larger directories such as generated, pub & vendor.

Copy compose.dev-ssh.yaml to compose.dev.yaml before installing Magento to take advantage of this setup. Then, create an SFTP connection at Preferences -> Build, Execution, Deployment -> Deployment. Connect to localhost and use app for the username & password. You can set additional options for working with Magento in PhpStorm at Preferences -> Build, Execution, Deployment -> Deployment -> Options.

Note that you must use your IDE's SSH/SFTP functionality, otherwise changes will not be synced. To re-sync your host environment at any time, run:

bin/copyfromcontainer --all

Linux

Running Docker on Linux should be pretty straight-forward. Note that you need to run some post install commands as well as installing Docker Compose before continuing. These steps are taken care of automatically with Docker Desktop, but not on Linux.

Copy compose.dev-linux.yaml to compose.dev.yaml before installing Magento to take advantage of this setup.

Install necessary dependencies

To ensure proper functionality, the docker-magento setup requires a few system dependencies to be installed on Linux. To install these dependencies, please execute the following command from the terminal:

sudo apt install curl libnss3-tools unzip rsync

The host.docker.internal hostname

The host.docker.internal hostname is used on Docker for Mac/Windows to reference the Docker daemon. On Linux, this hostname does not exist.

This hostname is hard-coded in the php.ini file. To make this hostname resolve, add "host.docker.internal:172.17.0.1" to the app.extra_hosts parameter of compose.yaml, replacing 172.17.0.1 with the result of:

docker run --rm alpine ip route | awk 'NR==1 {print $3}'

You must also create a new entry in your /etc/hosts file using the same IP:

172.17.0.1 host.docker.internal

Extra settings

To enable Xdebug on Linux, you may also need to open port 9003 on the firewall by running:

sudo iptables -A INPUT -p tcp --dport 9003 -j ACCEPT

You may also have to increase a virtual memory map count on the host system which is required by Elasticsearch.

Add the following line to the /etc/sysctl.conf file on your host:

vm.max_map_count=262144

Blackfire.io

These docker images have built-in support for Blackfire.io. To use it, first register your server ID and token with the Blackfire agent:

bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}

Next, open up the bin/start helper script and uncomment the line:

#bin/root /etc/init.d/blackfire-agent start

Finally, restart the containers with bin/restart. After doing so, everything is now configured and you can use a browser extension to profile your Magento store with Blackfire.

Cloudflare Tunnel

These docker images have built-in support for Cloudflare Tunnel. It can be useful for testing implementations that require some third-party integrations involving allow-listing domains. Since your local app cannot be allow-listed by other services, you can use Cloudflare Tunnel to get a public hostname that can be allow-listed on the other service.

To use it:

  • First, create a tunnel in Cloudflare Zero Trust and add the token to env/cloudflare.env.
  • Next, uncomment Cloudflare Tunnel section in main compose.yaml.
  • Finally, restart the containers with bin/restart.

In Cloudflare Tunnel configuration, configure the service URL to use type HTTPS and a URL of {name of app container}:{HTTPS port of app container}. For examplem, demo-app-1:8443. Enable the No TLS Verify option, since our local certificates are self-signed. You should now be able to access your app via the public hostname defined in Cloudflare Tunnel.

NOTE: Do not leave instances with Cloudflare Tunnel enabled running long-term, as your instance is publicly available to the world. You should ideally turn off tunnel container once testing is finished.

MFTF

To work with MFTF you will need to first enable the selenium image in the compose.dev.yaml file. Then, you will need to run the following.

  1. Run mftf build process bin/mftf build:project. This should build the basic setup for mftf in your project.
  2. Update the extra_host values to match your Magento URL and IP in compose.dev.yaml.
  3. Update the values in src/dev/tests/acceptance/.env, including adding the new line SELENIUM_HOST=selenium to define the host Codeception should connect to.
  4. Run a sample test bin/mftf run:test AdminLoginSuccessfulTest.
  5. Update your nginx.conf file to allow access to the dev section with the following, before the final deny all section:
location ~* ^/dev/tests/acceptance/utils($|/) {
    root $MAGE_ROOT;
    location ~ ^/dev/tests/acceptance/utils/command.php {
        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

For debugging, you can connect to the selenium image using a VCN client.

  • Connect with the VCN option and 127.0.0.1:5900, (default password: secret)
  • Run bin/mftf doctor to validate all sections are setup correctly.

Find more info here about mftf configuration.

Grunt + LiveReload for Frontend Development

Create a new theme and make it active

Create your new theme at app/design/frontend/VendorName/theme-name, with the related composer.json, registration.php and theme.xml files.

Make your new theme active at Admin > Content > Design > Configuration. Click the Edit button next to Global Scope, and set the Applied Theme to your new theme name, and click Save Configuration.

Load the LiveReload client file

To create a connection to LiveReload, you'll need to insert the LiveReload script into your theme. You can do this by creating a file in your theme at Magento_Theme/layout/default_head_blocks.xml with the contents:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script defer="true" src="/livereload.js?port=443" src_type="url"/>
    </head>
</page>

The "?port=443" parameter is important, otherwise the livereload.js script won't work.

While we're at it, let's also create an initial LESS file so we have something to test. Create a new file in your theme at web/css/source/_extend.less with the contents:

body {
    background: white;
}

You'll need to clear the Magento cache to enable your module, and make sure this layout XML update is properly loaded.

Your new theme should now be active at https://yourdomain.test. Since this is a new theme, it should appear the same as the parent theme defined in your theme.xml file, which is usually Blank.

Set up Grunt

Run bin/setup-grunt. This will set up the Grunt configuration files for your new theme. It's important to run this step after setting up your new theme, not before.

Start the Grunt watcher

Grunt can watch for filesystem changes by running bin/grunt watch. You can optionally pass in the --verbose or -v flag to toggle verbose mode on. This will let you know what's going on under the hood, so you can be sure it is compiling & watching the correct files, and updating them as changes are made.

LiveReload Browser extension

Running the grunt watch process also spawns the LiveReload server. Your browser needs to connect to this server, and this is done by installing the LiveReload browser extension.

In your browser, be sure to also open the Google Chrome Dev Tools, go to the Network tab, and click "Disable cache". This will ensure the browser does not long-cache static file assets, such as JavaScript & CSS files, which is important during development.

Ensure the LiveReload browser icon has been toggled on, and refresh the page. We can confirm the LiveReload script is loaded by going to the Network tab and ensuring the livereload.js file is loaded, and that it also spawns off a new websocket request to /livereload.

Test LiveReload

Since this is all set, let's update the CSS file to a different background color:

body {
    background: blue;
}

Upon saving this file, we will see the Grunt watcher detect the changes, and your browser should automatically load the new style without you needing to refresh the page, and without a full browser refresh.

PHP-SPX

The images also have additional profiler-tracers built-in to the Web UI.

To access the control panel, just open the following URL: https://magento.test/?SPX_UI_URI=/

Suggested Configuration

  • Enabled: Checked
  • Automatic start: Checked
  • Profile internal functions: Unchecked
  • Sampling: 5ms
  • Max profiling depth: Unlimited
  • Additional metrics: Unselected

Changing any options on this page set cookies for the domain for these settings. After then visiting a page on the frontend, you can navigate back to the GUI and scroll to the bottom of the page, and click the related request to view the trace of the request & response.

Profiling is also possible via command line, or curl:

SPX_REPORT=full SPX_ENABLED=1 SPX_SAMPLING_PERIOD=5000 bin/magento {command_name}
curl --cookie "SPX_REPORT=full; SPX_ENABLED=1; SPX_SAMPLING_PERIOD=5000" https://magento.test/

Additional information of how to work with SPX is available at https://www.youtube.com/watch?v=xk-JiBLsKfA

Known Issues

There are currently no large known issues or workarounds needed to use docker-magento with your Magento project. If you find any, please report them!

Credits

M.academy

This course is sponsored by M.academy, the simplest way to learn Magento.

M.academy

Mark Shust

My name is Mark Shust and I'm the creator of this repo. I'm a 6X Adobe Commerce Certified Developer and have been involved with Magento since the early days (v0.8!). I create technical education courses full-time for my company, M.academy.

License

MIT

docker-magento's People

Contributors

bbakalov avatar dependabot[bot] avatar dk4software avatar dmanners avatar drpayyne avatar freezy-sk avatar h3xx avatar ifiokjr avatar joggienl avatar kmilodenisglez avatar markshust avatar massalinux avatar michaellehmkuhl avatar peakercope avatar piotrkwiecinski avatar pniel-cohen avatar pykettk avatar r-martins avatar rafaelstz avatar rangerz avatar rnicklin avatar samuelecarpene avatar seb2nim avatar shkoliar avatar shochdoerfer avatar torhoehn avatar tuvandev avatar u-maxx avatar yevhenzvieriev avatar zsoerenm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-magento's Issues

composer authentication failed

When deploying the docker-compose on my digital ocean server (make with the docker-machine create command) I get this composer error.

[Composer\Downloader\TransportException]
The 'https://repo.magento.com/packages.json' URL required authentication.
You must be using the interactive console to authenticate

When i change the volume of app data to ./composer/.compose (and ofcourse create the nessesary auth.json in this folder) it works locally, but not when deploy it on my production server. I google the problem and found that there is also a command that can be used:

CMD composer config --global http-basic.repo.magento.com PUBLIC_KEY PRIVATE_KEY

to set the correct auth.json. Sadly this didnt do much either. Any idea whats wrong?

Which container has cron running? (indexes not being updated)

Which container runs the cron job? Without cron jobs running you cannot do updates, and indexes will not necessarily be synced. I got the warning coming up about indexes being out of date, and check that cron jobs are running. (There are 3 of them.)

MacOSX :- Non Writable Paths

In MacOSX Sierra, Docker (1.13.0) i see following error

>docker exec shoprunnermagento_phpfpm_1 tail -100f ./var/log/update.log
[2017-01-28 04:58:05] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 04:59:02] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:00:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:01:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:02:02] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:03:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:04:02] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:05:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:06:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:07:03] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []
[2017-01-28 05:08:02] update-cron.ERROR: Cron readiness check failure! Found non-writable paths: 	/var/www/html/bin/magento [] []```

Setup finishes but no Magento

After running docker-compose up, it says it finished the installation and setup. When I hit http://localhost:80, however, I get a 404 (I verified that port 80 is forwarding to the nginx install). Here's the output:

setup_1   | Running Magento 2 setup script...
setup_1   | Could not open input file: /src/bin/magento
setup_1   | Reindexing all indexes...
setup_1   | Could not open input file: /src/bin/magento
setup_1   | Deploying static view files...
setup_1   | Could not open input file: /src/bin/magento
setup_1   | Applying ownership & proper permissions...
setup_1   | find: `pub': No such file or directory
setup_1   | find: `pub': No such file or directory
setup_1   | find: `/src/var/generation': No such file or directory
setup_1   | The setup script has completed execution.
magento2dockercompose_setup_1 exited with code 0
app_1     | 172.17.42.1 - - [20/Jan/2016:19:52:02 +0000] "GET / HTTP/1.1" 404 168 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0" "-"

Did I miss a step?

Clean install not working

Ubuntu 16.04 docker and docker-compose

mysql and apache2 not installed

appdata and dbdata always exit and http://m2.localhost:8000/ give not found

appdata setting in .yml

appdata:
image: tianon/true
volumes:

- /var/www/html

- ~/.composer:/var/www/.composer
- ./html/app/code:/home/mhmd/Desktop/docker-projects/magento2-docker-compose/html/app/code
- ./html/app/design:/home/mhmd/Desktop/docker-projects/magento2-docker-compose/html/app/design

File changes dose not sync with appdata container

Hi,

I have changed the appdata volume's mount point to - ./www:/srv/www and restart the containers but my changes on my local folder ./www was not sync with appdata volume. Can any help me to resolve this.

Thanks
Mari S

m2.localhost:8000 does not work

Thanks for the great article and images.
I am able to get the site up and running if I use just localhost:8000 in docker-compose.yml. However, if I use m2.localhost:8000 I get a server not found.
Is there an additional configuration step to get m2.localhost:8000 to work?

Unable to install Magento 2

I tried to install magento2 with your docker-compose file, but got following error:
Why it's happened? Any ideas how to fix it? Looks like this issue related to https://github.com/magento/magento2-community-edition/issues/15

phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
symfony/dependency-injection suggests installing symfony/proxy-manager-bridge (Generate service proxies to lazy load them)
sjparkinson/static-review suggests installing sensiolabs/security-checker (Required for ComposerSecurityReview.)
lusitanian/oauth suggests installing symfony/http-foundation (Allows using the Symfony Session storage backend.)
lusitanian/oauth suggests installing predis/predis (Allows using the Redis storage backend.)
Writing lock file
Generating autoload files



  [ErrorException]
  file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory



create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]


chmod: cannot access '/src/bin/magento': No such file or directory
Installing composer dependencies...
/usr/local/bin/m2setup.sh: 11: /usr/local/bin/m2setup.sh: /src/bin/magento: not found
Ignore the above error (bug in Magento), fixing with 'composer update'...
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files



  [ErrorException]
  file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory



update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--] [<packages>]...


Running Magento 2 setup script...
/usr/local/bin/m2setup.sh: 27: /usr/local/bin/m2setup.sh: /src/bin/magento: not found
Reindexing all indexes...
/usr/local/bin/m2setup.sh: 41: /usr/local/bin/m2setup.sh: /src/bin/magento: not found
The setup script has completed execution.

Also I tried replace image to mageinferno/magento2-setup:2.0.0 but get following error:

ocker-compose run --rm setup
Starting test_dbdata_1
Pulling setup (mageinferno/magento2-setup:2.0.0)...
2.0.0: Pulling from mageinferno/magento2-setup
5bac9e9b1edc: Pull complete
1e676c810de2: Pull complete
a02b4754c021: Pull complete
f192cde5963d: Pull complete
Digest: sha256:6afcfe7c4ae4ae4a466ed68d69c920a3a59cbffcaf29a2dd8afc85c22cc9e5a7
Status: Downloaded newer image for mageinferno/magento2-setup:2.0.0
Initializing setup...

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
chmod: cannot access '/src/bin/magento': No such file or directory
Running Magento 2 setup script...
/usr/local/bin/m2setup.sh: 15: /usr/local/bin/m2setup.sh: /src/bin/magento: not found
Reindexing all indexes...
/usr/local/bin/m2setup.sh: 28: /usr/local/bin/m2setup.sh: /src/bin/magento: not found
The setup script has completed execution.```

Permission denied errors

I can't make a new directory or copy files to ./html/app/design. I'm getting permission denied errors. I tried the docker cp CONTAINERID:/var/www/html ./ but I get chmod: operation not permitted error.

Source code volume

Is it possible to setup the source code volume before running the setup cmd :
docker-compose run --rm setup

So I don't have to copy files from container to my machine in order to start developing a module.
In fact, I want the hole source code to be in my machine including vendor,cache.. so I can explore magento core and phpstorm can index better.

I added this code to my docker-compose-override.yml:

appdata:
  volumes:
    - ../code:/var/www/html

Then , setup wont work telling my that


  [InvalidArgumentException]          
  Project directory ./ is not empty. 

php memory issue 'Allowed memory size of 2097152 bytes exhausted'

Using current version docker-compose file.
On fresh (volumes was deleted) install.

With diff:

$ diff ./docker-compose.yml ./docker-compose2.ym
12c12
<     - 80:80
---
>     - 8000:80
17c17
<     - mageAD:/var/www/html
---
>     - /var/www/html
44c44
<     - mageDB:/var/lib/mysql
---
>     - /var/lib/mysql
58c58
<     - M2SETUP_BASE_URL=http://m2.localhost:80/
---
>     - M2SETUP_BASE_URL=http://m2.localhost:8000/
61c61
<     - [email protected]
---
>     - [email protected]

Receive:
phpfpm_1 | Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes) in /var/www/html/vendor/zendframework/zend-modulemanager/src/ModuleManager.php on line 8

Main page loads. But not admin uri (used proper uri docker exec magento2_phpfpm_1 magento info:adminuri)

phpfpm_1   | 172.17.0.3 -  11/Nov/2016:12:57:30 +0000 "GET /index.php" 302
app_1      | 172.17.0.1 - - [11/Nov/2016:12:57:30 +0000] "GET /index.php/admin_9gkfm7/admin/index/index/key/f24a62a98b62ea5b1c0038ff548f76859ded621f96fc6590910c9c055d736676/ HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.90 Safari/537.36" "-"

Reacieving in browser:

The m2.localhost page isnโ€™t working

m2.localhost redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

Can't install Enterprise Edition using docker-compose

I've been trying to install the Enterprise Edition using the *.yml and instructions provided but I simply can't complete the execution, as explained below. It works for the Community Edition using both Archiver or Composer (M2SETUP_USE_ARCHIVE=true/false).

I am currently trying to use everything exactly like it is commited by the author and changing only the required fields, as follow:

#setup.env

M2SETUP_DB_HOST=db
M2SETUP_DB_NAME=magento2
M2SETUP_DB_USER=magento2
M2SETUP_DB_PASSWORD=magento2
M2SETUP_BASE_URL=http://localhost:8000/
M2SETUP_ADMIN_FIRSTNAME=Admin
M2SETUP_ADMIN_LASTNAME=User
[email protected]
M2SETUP_ADMIN_USER=magento2
M2SETUP_ADMIN_PASSWORD=magento2
M2SETUP_VERSION=2.1.5
M2SETUP_USE_SAMPLE_DATA=false
M2SETUP_USE_ARCHIVE=false
M2SETUP_USE_COMPOSER_ENTERPRISE=true

Both mysql.env and docker-compose.yml are unchanged.

I start the execution with docker-compose run --rm setup, it asks for my credentials and after inputing them I see the following error:

magento

On my second try, I created the ~/.composer/auth.json file, uncommented the pertinent lines, renamed docker-compose.override.yml and executed the same command again. This time I haven't been asked for my credentials and the exactly same error showed up.

Additional info:
I've tested this using docker-compose on both OSX and Ubuntu (VM).

Ubuntu: docker-compose version 1.11.2, build dfed245
OSX: Installed with Homebrew (can't access the machine to check the version now, but should be the lastest one available today)

Any solution or something I am doing incorrectly?

bin/magento is assumed to be a php script (not sh) by test framework

The integration test framework calls bin/magento multiple times to uninstall and install Magento in the testing database.
It does so with a command like

/usr/local/bin/php -f '/var/www/html/bin/magento' setup:install -vvv --db-host='docker_db_1' --db-user='magento2_test' --db-password='123123q' --db-name='magento_integration_tests' --backend-frontname='backend' --admin-user='user' --admin-password='password1' --admin-email='[email protected]' --admin-firstname='firstname' --admin-lastname='lastname' --magento-init-params='MAGE_DIRS[etc][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/etc&MAGE_DIRS[var][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var&MAGE_DIRS[media][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/pub/media&MAGE_DIRS[static][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/pub/static&MAGE_DIRS[generation][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/generation&MAGE_DIRS[cache][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/cache&MAGE_DIRS[log][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/log&MAGE_DIRS[session][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/session&MAGE_DIRS[tmp][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/tmp&MAGE_DIRS[upload][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/var/upload&MAGE_DIRS[pub][path]=/var/www/html/dev/tests/integration/tmp/sandbox-0-a06c5218c942e8428d1719573e5cf3bc/pub&MAGE_MODE=developer' 2>&1

Because the mageinferno docker image replaces bin/magento with a bash script (assumably to change the UID) this fails, but doesn't even register as a failure since PHP processes that file as a plain text file without <?php tags. It just outputs it's contents to stdout.

In order to be able to use the docker images to run integration tests bin/magento has to be a php script. Depending on why the UID is changed, the same effect might be achieved using by setting the suid or sgid bits.

Fatal error: Uncaught Zend_Cache_Exception

After running docker-compose up, all of the containers load, but I get a fatal PHP error:

Fatal error: Uncaught Zend_Cache_Exception: cache_dir "/src/var/page_cache" is not writable in /src/vendor/magento/zendframework1/library/Zend/Cache.php:209 
Stack trace: 
#0 /src/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException('cache_dir "/src...')
#1 /src/lib/internal/Cm/Cache/Backend/File.php(82): Zend_Cache_Backend_File->setCacheDir('/src/var/page_c...')
#2 /src/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct(Array)
#3 /src/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true)
#4 /src/vendor/magento/framework/App/Cache/Frontend/Factory.php(154): Zend_Cache::factory('Magento\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, true, true)
#5 /src/vendor/magento/framework/App/Cache/Frontend/Pool.php(67): Magento\Framework\App\Cache\Frontend\Factory->create(Array)
#6 /src/vendor/magento/framework/App/Cache/Frontend/Pool.php(146): Magento\Framework\App\Cach in /src/vendor/magento/zendframework1/library/Zend/Cache.php on line 209

Please help!

MAGE_MODE environment configuration variable leads to inconsistencies

The command bin/magento deploy:mode:set <MODE> writes the target deploy mode to the file app/etc/env.php.
Unfortunately Magento also supports setting the run mode via environment variables, which easily leads to inconsistent state between commands and web requests being processed.
For that reason I recommend never using the environment to set the run mode and only use the file app/etc/env.php.
In the current training where we are using the your set of images this inconsistency happens frequently. I would like to suggest removing the setting of MAGE_MODE in the environment.

Running integration and unit tests

Running M2 unit tests is possible via docker-compose run --rm vendor/bin/phunit -c dev/tests/unit/phpunit.xml.dist, but running integration tests fails because of three things.

  1. bin/magento has to be a PHP script as it is called to install and uninstall Magento into a test DB (reference #40)
  2. The current working directory has to be dev/tests/integration
  3. The command line mysql and mysqldump utilities have to be available because the testing framework uses those to create a dump after the initial install and import that on subsequent runs.

I've fiddled with the mageinferno images to get this working, which it now seems to do.

Solving the issue of bin/magento not being a PHP script please refer to #40

To solve the second and third issue I've done the following (with the help and hand-holding of James Cowie and Anton Siniorg):

Create the file Docker/integration-test-container/Dockerfile with the following contents:

FROM mageinferno/magento2-php:7.0-fpm-0

MAINTAINER [email protected]

RUN apt-get update

RUN apt-get install -y mysql-client

WORKDIR /var/www/html/dev/tests/integration

ENTRYPOINT ["/usr/local/bin/php", "../../../vendor/bin/phpunit"]

CMD [""]

Add this to the docker-compose.yml file:

integration:
  build: Docker/integration-test-container
  volumes_from:
    - appdata
  links:
    - db

unit:
  image: mageinferno/magento2-php:7.0-fpm-0
  command: php vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist
  volumes_from:
    - appdata

The unit service isn't really required, but I like it because it can be run using docker-compose run unit which reads nice.
It also enforces good practice by not linking to the DB since that should not happen in unit tests anyway.

The integration test suite can be run using

$ docker-compose run --rm integration

Because the current working directory is dev/tests/integration, individual tests can be started by specifying the path relative to that directory

$ docker-compose run --rm integration ../../../app/code/Example/Module/Test/Integration`

Cloned, Ran Setup, but not resolving URL in browser..

Hi Mark,

Sorry I was too quick on the draw :) Just trying to get your project working on OS X with latest versions of Docker, Docker-compose, Docker-machine. It looks like it installs correctly, but no code is contained on localhost (I uncommented the localhost volume)

I am guessing this is something simple - Do you still need dinghy for this project?

Here is a pastebin of the install process: http://pastebin.com/QfqRZruP

Magento Admin Credentials

Once installed, I'm trying to get a way to authenticate as an admin into the fresh instance. To get the admin URL to use, I issued:

docker exec -it magento_phpfpm_1 ./bin/magento info:adminuri

It gave me the URL I needed to use. Now from that URL, what's the admin username / password?

Running tests

How I can run M2 tests on this docker? There is no php5-cli package installed

Is this working?

I get no /srv/www/ folder in my container. Tried on ubuntu and mac.

Pulled the images, copied this docker compose file and followed the instructions from the readme.

When running docker cp afbc12492752:/srv/www ./ I get no www folder.

Error during setup process

I copied the docker-compose.yml from this repo and run the following command to setup m2:

docker-compose run --rm setup

It responses:

SQLSTATE[HY000] [2002] No route to host.

[InvalidArgumentException]
Parameter validation failed

Any ideas of what could be the causes?

Thanks

Invalid service name "php-fpm"

When running this docker-compose.yml script with docker-compose up, I get this output:

user@desktop:/home/dpurcell/dev2/magento2-docker-compose# docker-compose up
Invalid service name "php-fpm" - only [a-zA-Z0-9] are allowed

Here's my docker-compose version:

user@desktop:/home/dpurcell/dev2/magento2-docker-compose# docker-compose -v
docker-compose version: 1.3.1
CPython version: 2.7.10
OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015

What am I doing wrong?

Cant start setup container

Something happended pretty recently - Now I can not bootup the setup anymore

git clone https://github.com/mageinferno/magento2-docker-compose.git
docker-compose run --rm setup

Starting magento2dockercompose_appdata_1
Starting magento2dockercompose_dbdata_1
Starting magento2dockercompose_db_1
ERROR: Cannot link to a non running container: /magento2dockercompose_db_1 AS /magento2dockercompose_setup_run_9/db

Stop/Restart docker-compose returns errors

Is there any literature for stopping containers properly. Looks like whenever running docker-compose down and docker-compose up -d app nginx returns a 404 error.

Any ideas?

app/code

Where does the app/code directory come from in the readme? This isn't a standard Magento directory?

Host not found?

Just tried to spin this up and got this error:

1#1: host not found in upstream "php-fpm:9000" in /etc/nginx/conf.d/default.conf:2
nginx: [emerg] host not found in upstream "php-fpm:9000" in /etc/nginx/conf.d/default.conf:2

Any Idea how to resolve?

Deprecated Functionality: Function mcrypt_module_open() is deprecated with php:7.1-fpm-0

Try to install the version 2.1.4 and run into the deprecated exception if I use the php version magento2-php:7.1-fpm-0 in setup container.

There is no deprecated exception with magento2-php:7.0-fpm-0.

docker-compose.yml

setup:
  image: mageinferno/magento2-php:7.1-fpm-0
  command: /usr/local/bin/mage-setup
  links:
    - db
  volumes_from:
    - appdata
  env_file: env/setup.env

Command

$ docker-compose run --rm setup

Deprecated Exception

[Progress: 114 / 425]
Module 'Magento_Customer':
[Progress: 115 / 425]
Module 'Magento_BundleImportExport':
[Progress: 116 / 425]
Module 'Magento_CacheInvalidate':
[Progress: 117 / 425]
Module 'Magento_AdminNotification':
[Progress: 118 / 425]
Module 'Magento_Indexer':
Running schema recurring...


[Exception] Deprecated Functionality: Function mcrypt_module_open() is deprecated in /var/www/html/vendor/magento/framework/Encryption/Crypt.php on line 54

Project directory ./ is not empty

setup_1   | Installing magento/project-community-edition (2.1.2)
setup_1   | 
setup_1   |                                       
setup_1   |   [InvalidArgumentException]          
setup_1   |   Project directory ./ is not empty.  
setup_1   |                                       
setup_1   | 
setup_1   | create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]
setup_1   | 
setup_1   | ln: failed to create symbolic link './var/composer_home': No such file or directory
setup_1   | chmod: cannot access './bin/magento': No such file or directory
setup_1   | Installing composer dependencies...
setup_1   | The "hirak/prestissimo" plugin was skipped because it requires a Plugin API version ("~1.0.0-alpha10") that does not match your Composer installation ("1.1.0"). You may need to run composer update with the "--no-plugins" option.
setup_1   | Composer could not find a composer.json file in /var/www/html
setup_1   | To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
setup_1   | Could not open input file: ./bin/magento
setup_1   | Running Magento 2 setup script...
setup_1   | Could not open input file: ./bin/magento
setup_1   | The setup script has completed execution.
magento2dockercompose_setup_1 exited with code 0
phpfpm_1  | Could not open input file: /var/www/html/bin/magento-php
phpfpm_1  | Could not open input file: /var/www/html/update/cron.php
phpfpm_1  | Could not open input file: /var/www/html/bin/magento-php

My docker-compose.override.yml file

phpfpm:
  environment:
    - PHP_MEMORY_LIMIT=4G
    - MAGE_APP_MODE=dev

appdata:
  volumes:
    - ~/.composer:/var/www/.composer
    - ./html/app/code:/var/www/html/app/code
    - ./html/app/design:/var/www/html/app/design

setup:
  environment:
    - PHP_MEMORY_LIMIT=4G
    - MAGE_APP_MODE=dev
    - M2SETUP_USE_SAMPLE_DATA=true
    - M2SETUP_USE_ARCHIVE=false

docker-compose.yml has not been touched.

What I did was

$ git clone https://github.com/mageinferno/magento2-docker-compose.git
$ cd magento2-docker-compose
// changed docker-compose.override.yml
$ docker-compose up

Kitematic Not working with this.... any ideas?

When you run kitematic you get this screen - and opening the weblink doesn't work

image

it just generates this page:
image

This may be a relevant issue - however it might be down to someone in the community who knows about Kitematic and Docker more that can make a relevant suggestion to help this project support Kitematic:

docker/kitematic#550

mysite.com

Hello,

There's something wrong with VIRTUAL_HOST in the docker-compose.yml, because even if I change it to localhost or xxxx and rebuild all docker images, the magento web site always refere to http://mysite.com ...

Run PHP Composer

What is the recommended way to run php composer to install a module?

Fatal error: Uncaught ErrorException: session_write_close()

It looks like you're making great progress. I tried the install and received the errors below. I'm not sure that it's breaking anything, but it seems like it is worth a look.

[Progress: 361 / 362]
Post installation file permissions check...
For security, remove write permissions from these directories: '/src/app/etc'
[Progress: 362 / 362]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_12j6z3

Fatal error: Uncaught ErrorException: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/src/var/session/) in /src/vendor/magento/framework/Session/SessionManager.php:139
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'session_write_c...', '/src/vendor/mag...', 139, Array)
#1 /src/vendor/magento/framework/Session/SessionManager.php(139): session_write_close()
#2 [internal function]: Magento\Framework\Session\SessionManager->writeClose()
#3 {main}
  thrown in /src/vendor/magento/framework/Session/SessionManager.php on line 139
Reindexing all indexes...
Customer Grid index has been rebuilt successfully in 00:00:00
Category Products index has been rebuilt successfully in 00:00:00
Product Categories index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:00
Product EAV index has been rebuilt successfully in 00:00:00
Stock index has been rebuilt successfully in 00:00:00
Catalog Search index has been rebuilt successfully in 00:00:02
Catalog Rule Product index has been rebuilt successfully in 00:00:01
Catalog Product Rule index has been rebuilt successfully in 00:00:00

Fatal error: Uncaught ErrorException: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/src/var/session/) in /src/vendor/magento/framework/Session/SessionManager.php:139
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'session_write_c...', '/src/vendor/mag...', 139, Array)
#1 /src/vendor/magento/framework/Session/SessionManager.php(139): session_write_close()
#2 [internal function]: Magento\Framework\Session\SessionManager->writeClose()
#3 {main}
  thrown in /src/vendor/magento/framework/Session/SessionManager.php on line 139
Deploying static view files...
Requested languages: en_US
=== frontend -> Magento/blank -> en_US ===
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Successful: 1965 files; errors: 0

---

Developer mode

Hi,

as soon as i activate the developer mode with docker-compose exec phpfpm ./bin/magento deploy:mode:set developer , my custom css and scripts.js in not generated in static directory, or at least i get an 404 error. Is it maybe connected to the nginx config?

Regards,
Remklov

Can't shared folder between Host and Container

Hello,

I'm trying to follow all the steps to create a dev environment with Docker, but when I try to shared folder to start editing something in Magento, I could not see any file into the container. I'm using Windows 10, my Docker version is 1.12.0-rc4-beta20(build 5579).

The folders seems to be mounted but when I try to see the files, the folders are empty.

Any idea what can I do?

Permission Error

Hey there,

thanks a lot for your awesome image. However, I'm struggling to get this up and running. I read about the magento file permission problem and that your script fixes them. However, it's not working on my machine here. I'm also using dinghy as you guys do. The setup script is not able to chown the files

chown: changing ownership of '/srv/www/vendor/magento/magento2-base/dev/tests/functional/tests/app/Magento/Backup/Test/Page/Adminhtml': Operation not permitted
chown: changing ownership of '/srv/www/vendor/magento/magento2-base/dev/tests/functional/tests/app/Magento/Backup/Test/Page': Operation not permitted
chown: changing ownership of '/srv/www/vendor/magento/magento2-base/dev/tests/functional/tests/app/Magento/Backup/Test/TestCase/NavigateMenuTest.xml': Operation not permitted
chown: changing ownership of '/srv/www/vendor/magento/magento2-base/dev/tests/functional/tests/app/Magento/Backup/Test/TestCase': Operation not permitted

Any ideas? :) Thanks!

Configurable git repo

Can you configure which git repo we want to use? Not all the times you want to run a brand-new copy of Magento2 from scratch. I want to migrate my existing project to Docker and it would be awesome if that could be configured.

sending emails does not work

Hello,

first of all: great work! the setup works quite well! However sending emails does not really work. Even after setting up sendmail, which works from the command line (both, in nginx as well as app container) magento does not send any emails. I installed ssmtp to send all emails via an external smtp server, still it doesn't work. I am running out of ideas what to try next. Any ideas? I wonder why sendmail works in the container and properly delivers emails but magento won't...

thanks
Peter

Problem Setting Up

Fixed by changing

  • ~/.composer:/var/www/.composer to
  • ~/.composer:/srv/www/.composer
    in docker-compose.yml

Hi,
After following all steps and running
docker-compose run --rm setup
I get :

Starting mangeto2_appdata_1
Starting mangeto2_dbdata_1
Creating mangeto2_db_1
Initializing setup...
Installing magento/project-community-edition (2.1.0)

[InvalidArgumentException]
Project directory ./ is not empty.

create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [] [] []

chmod: cannot access './bin/magento': No such file or directory
Running Magento 2 setup script...
Could not open input file: ./bin/magento
The setup script has completed execution.

How to access Magento Connect?

Hello,

Again, newbee with Magento here. Basically, after installing Magento using the docker-compose playbook, we would like to install an extension, but the Magento Connect link as per mentioned from their docs doesn't exist in the System tab of the admin panel.

I've tried contacting Magento about it, but they seem to think the best place for the issue is right here (See this thread).

Any clue please?

Running Magento 2 setup script... No route to host

docker-compose run --rm setup

Running Magento 2 setup script...
SQLSTATE[HY000] [2002] No route to host

[InvalidArgumentException]
Parameter validation failed

docker-compose up -d app

Localhost:8000

Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\App\Config\Scope\ReaderPoolInterface in /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:73 Stack trace: #0 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(71): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\Framewo...') #1 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(126): Magento\Framework\ObjectManager\ObjectManager->get('Magento\Framewo...') #2 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(53): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'readerPool', 'Magento\Framewo...') #3 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(82): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments('Magento\Framewo...', Array, Array) #4 /var/www/html/vendor/magento/framework/Object in /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
f28e55bff353 mageinferno/magento2-nginx:1.11-0 "/usr/local/bin/start" 18 minutes ago Up 18 minutes 443/tcp, 0.0.0.0:8000->80/tcp magento2dockercompose_app_1 4.097 kB (virtual 181.4 MB)
e64e30f51802 mageinferno/magento2-php:7.0-fpm-0 "/usr/local/bin/start" 18 minutes ago Up 18 minutes 9000/tcp magento2dockercompose_phpfpm_1 529 B (virtual 593.6 MB)
d940031ebaab redis:latest "docker-entrypoint.sh" 45 minutes ago Up 45 minutes 6

Can't Log into Admin side.

I've built the containers and have successfully loaded up my site, however when I got to log in to the admin side, the username magento2 and password magento2 don't seem to do anything.

No error message is thrown i'm just redirected to the admin sign in page again.

I've confirmed the Admin user exists:

My code is hosted at this repo. https://github.com/ajmyers01/magento_docker

I"m unsure if maybe the DB container isn't hooked up to the app correctly or something.

Thanks for your help and the great repo !

Copying /var/www/html from appdata volume fails

I have followed the setup guide using the composer auth method and everything installs and runs great. My problem is that when I attempt to copy the filesystem as described in the README, I get the following:

C:\Users\NathanS\mage2>docker cp 81a:/var/www/html ./
symlink \var\www\.composer C:\Users\NathanS\mage2\html\var\composer_home: A required privilege is not held by the client.

I have tried using the command prompt as well as git-bash (Mingw64) both with the same result. I have tried many different things to bypass this issue but have had no success. I also can't find anybody else talking about this problem.

I am on 64bit Windows 10 Enterprise running as an Administrative user.

What can I do to get this to work?

Issue on index.php

Hi,

I got an issue when browsing the index page :

magento2

Fatal error: Uncaught Error: Call to a member function getValue() on boolean in /src/vendor/magento/module-catalog/Pricing/Render/FinalPriceBox.php:101 Stack trace: #0 /src/vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml(24): Magento\Catalog\Pricing\Render\FinalPriceBox->hasSpecialPrice() #1 /src/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/src/vendor/mag...') #2 /src/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Pricing\Render\FinalPriceBox), '/src/vendor/mag...', Array) #3 /src/vendor/magento/framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/src/vendor/mag...') #4 /src/vendor/magento/framework/Pricing/Render/PriceBox.php(65): Magento\Framework\View\Element\Template->_toHtml() #5 /src/vendor/magento/module-catalog/Pricing/Render/FinalPriceBox.php(31): Magento\Framework\Pricing\Render\PriceBox->_toHtml() #6 /src/vendor/magento/framework/Vi in /src/vendor/magento/module-catalog/Pricing/Render/FinalPriceBox.php on line 101

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.