Code Monkey home page Code Monkey logo

docker-magento2's Introduction

docker-magento2

Docker Automated Build Docker Build Status

A base Magento 2 image that can be used to scale in production. This can be used in combination with MySQL and Redis. It is opinionated and includes support for Composer, ionCube, Redis, OPcache, and the required PHP modules for a basic Magento installation.

It does not include Magento.

Usage

An example Dockerfile

FROM sensson/magento2
COPY src/ /var/www/html/

More details can be found in Magento2 and Docker.

Persistent storage

The container assumes you do not store data in a folder along with the application. Don't use Docker volumes for scale. Use CephFS, GlusterFS or integrate with S3 or S3-compatible services such as Fuga.io.

Configuration

Environment variables

Environment variable Description Default
MYSQL_HOSTNAME MySQL hostname mysql
MYSQL_USERNAME MySQL username root
MYSQL_PASSWORD MySQL password secure
MYSQL_DATABASE MySQL database magento
CRYPTO_KEY Magento Encryption key Emtpy
URI Uri (e.g. http://localhost) http://localhost
RUNTYPE Set to development to enable Empty
ADMIN_USERNAME Administrator username admin
ADMIN_PASSWORD Administrator password adm1nistrator
ADMIN_FIRSTNAME Administrator first name admin
ADMIN_LASTNAME Administrator last name admin
ADMIN_EMAIL Administrator email address [email protected]
BACKEND_FRONTNAME The URI of the admin panel admin
CURRENCY Magento's default currency EUR
LANGUAGE Magento's default language en_US
CONTENT_LANGUAGES The languages used in Magento en_US
TIMEZONE Magento's timezone Europe/Amsterdam
CRON Run as a cron container false
UNATTENDED Run unattended upgrades false

Include the port mapping in URI if you run your shop on a local development environment, e.g. http://localhost:3000/.

Hooks

Hooks allow you to run certain actions at certain points in the startup procedure without having to rewrite entrypoint.sh. You can use hooks to import data, preconfigure settings or run other scripts that need to run each startup sequence.

Hook point Location Description
Pre install /hooks/pre_install.sh Runs before an installation or update.
Pre compile /hooks/pre_compile.sh Runs before code compilation starts.
Post install /hooks/post_install.sh Runs after Magento has been installed.

You need to COPY any hooks to this location yourself.

Development mode

Setting RUNTYPE to development will turn on public error reports. Anything else will leave it off. It will also set display_errors to on in PHP. This is set to off by default.

A basic docker-compose.yml has been provided to help during the development of this image.

docker-magento2's People

Contributors

ju5t avatar obuchmann 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

Watchers

 avatar  avatar  avatar  avatar

docker-magento2's Issues

Example does not work out of the box

Hi, on running the example it immediately fails to work on mac mojave.

magento-frontend | Waiting on database connection..

Similarly the cron container has the same issue. Can you confirm that the example still works?

A little digging and this seems to be the cause:

root@5a55d523cd70:/var/www/html# mysqladmin ping -h"mysql" mysqladmin: connect to server at 'mysql' failed error: 'Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory'

'sockets' extension missing on install magento 2.3.4

I created a plain src from magento community

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

When I reach command: bin/magento setup:install

following error shows up

In Installer.php line 521:
                                           
  Missing following extensions: 'sockets'  

can be fixed with docker-php-ext-install sockets

I think this php extension should be installed.

Installer runs on every container start

The installer runs on every container start. The check that is supposed to handle this fails.

if [[ $(bin/magento setup:db:status) == *"not installed"*. ]] || [[ $(bin/magento setup:db:status) == *"none"*. ]]; then

When a container starts we still see Running installer..

Git is not included

When you try to import from git with Composer it returns sh: 1: git: not found. Git should be added to the Dockerfile.

Add hooks that can run after the installation has completed

As a developer I would like to be able to run scripts automatically at certain points in the start up process. This allows me to make changes such as adding customers and products or reconfiguring settings in a development, or even production, environment.

Improve permission handling

A chmod at the end of entrypoint.sh increases the startup time. It would be better to use COPY --chown and run every command in entrypoint.sh as the www-data-user.

Enable maintenance mode during unattended upgrades

Magento can enable maintenance through bin/magento maintenance:enable. This will set var/.maintenance.flag and/or var/.maintenance.ip in case any ip addresses have been whitelisted.

Unless you have shared storage like NFS this will not work in clustered environments.

Cronjobs

Magento needs cronjobs to function. A simple entrypoint that starts cron based on an environment variable could be sufficient.

Issue running the example

I wanted to run the example and check out the environment. When I run docker-compose up -d i get the containers to keep restarting:
image

Am I missing something?

Unable to connect to database since mysql upgrade

The mysql:latest image has recently been updated to version 8 and as a result the frontend container can no longer establish a database connection.

I would propose pinning the mysql image to version 5.7.23.

services:
  mysql:
-    image: mysql:latest
+    image: mysql:5.7.23
    container_name: mysql
    restart: always

Initial setup is not handled

I try to install a fresh magento 2.3.4

Following problem occours in entrypoint.sh:
CHECK_STATUS evaluates to

No information is available: the Magento application is not installed.

and UNINSTALLED_PLUGINS to 0

then it tries to update the system instead of installing it

Security issue MYSQL_PASSWORD as ENV variable

Thanks for your great work, especially for this article.

Although we have carefully crafted this example it may contain bugs, security issues or other problems that we were not aware of at the time.

Here is what we do:
Using the swarm mode of Docker, we create Docker Secrets.

Instead of

MYSQL_PASSWORD | MySQL password | secure

we're using:

MYSQL_PASSWORD | MySQL password | secure or /run/secrets/MYSQL_PASSWORD

The place, where we need it, we do something like:

$password = $is_dev ?  $_ENV['MYSQL_PASSWORD'] : trim(file_get_contents($_ENV['MYSQL_PASSWORD'])),

So, if $is_dev, we can use it as plaintext, otherwise we get the output from our docker secret.

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.