Public | Automated Build

Last pushed: 8 months ago
Short Description
Docker image for Magento
Full Description

Docker image for Magento 1.x

This repo creates a Docker image for Magento 1.x.

Please note

The primary goal of this repo is to create Docker images for Magento 1.x development and testing, especially for extensions and themes development. It lacks essential support for production deployment, e.g. Varnish and Redis. Use this wisely for production deployment.

This repo is only for Magento 1.x. If you are looking for Magento 2.x, check out alexcheng1982/docker-magento2.

Magento versions

Version Git branch Tag name
1.9.2.4 master latest
1.9.1.1 1.9.1.0 1.9.1.0
1.8.1.0 1.8.1.0 1.8.1.0
1.7.0.2 1.7.0.2 1.7.0.2
1.6.2.0 1.6.2.0 1.6.2.0

How to use

Use as standalone container

You can use docker run to run this image directly.

docker run -p 80:80 alexcheng/magento

Then finish Magento installation using web UI. You need to have an existing MySQL server.

Magento is installed into /var/www/htdocs folder.

Use Docker Compose

Docker Compose is the recommended way to run this image with MySQL database.

A sample docker-compose.yml can be found in this repo.

web:
  image: alexcheng/magento
  ports:
    - "80:80"
  links:
    - mysql
  env_file:
    - env
mysql:
  image: mysql:5.6.23
  env_file:
    - env

Then use docker-compose up -d to start MySQL and Magento server.

Magento sample data

Installation script for Magento sample data is also provided.

Please note: Sample data must be installed before Magento itself.

Use /usr/local/bin/install-sampledata to install sample data for Magento.

docker exec -it <container id> install-sampledata

Magento 1.9 sample data is compressed version from Vinai/compressed-magento-sample-data. Magento 1.6 uses the official sample data.

For Magento 1.7 and 1.8, the sample data from 1.6 doesn't work properly as claimed in the offcial website and causes database errors, so the install-sampledata script is removed for 1.7 and 1.8.

Magento installation script

A Magento installation script is also provided as /usr/local/bin/install-magento. This script can install Magento without using web UI. This script requires certain environment variables to run:

Environment variable Description Default value (used by Docker Compose - env file)
MYSQL_HOST MySQL host mysql
MYSQL_DATABASE MySQL db name for Magento magento
MYSQL_USER MySQL username magento
MYSQL_PASSWORD MySQL password magento
MAGENTO_LOCALE Magento locale en_GB
MAGENTO_TIMEZONE Magento timezone Pacific/Auckland
MAGENTO_DEFAULT_CURRENCY Magento default currency NZD
MAGENTO_URL Magento base url http://local.magento
MAGENTO_ADMIN_FIRSTNAME Magento admin firstname Admin
MAGENTO_ADMIN_LASTNAME Magento admin lastname MyStore
MAGENTO_ADMIN_EMAIL Magento admin email admin@example.com
MAGENTO_ADMIN_USERNAME Magento admin username admin
MAGENTO_ADMIN_PASSWORD Magento admin password magentorocks1

If you want to use install-magento script and this images is started as a standalone container using docker run, make sure these environment variables are passed in docker run with -e switch.

After Docker container started, use docker ps to find container id of image alexcheng/magento, then use docker exec to call install-magento script.

docker exec -it <container id> install-magento

If Docker Compose is used, you can just modify env file in the same directory of docker-compose.yml file to update those environment variables.

After calling install-magento, Magento is installed and ready to use. Use provided admin username and password to log into Magento backend.

If you use default base url (http://local.magento) or other test url, you need to modify your host file to map the host name to docker container. For Boot2Docker, use boot2docker ip to find the IP address.

Important: If you do not use the default MAGENTO_URL you must use a hostname that contains a dot within it (e.g foo.bar), otherwise the Magento admin panel login won't work.

Redis Cache

If you want to use Redis as Cache backend see comments in Dockerfile and bin/install-magento

Modman

Modman is a Magento module manager that allows you to leave your work siloed from the actual Magento codebase via symlinks. With modman, you can sync plugin or theme work without keeping a persistent volume (or using a hidden volume).

# from htdocs
modman init
modman link /path/to/plugin

And to update symlinks:

modman deploy
Docker Pull Command
Owner
alexcheng
Source Repository

Comments (11)
agusddt
2 days ago

Hi there,
Great repo, thanks!
I 've managed to install all properly, works perfect!
Just have a question, I want to install a SSL certificate, and since apache server is embedded I cannot get it working, any help?

mistercinux
5 months ago

Hi there,

I had some troubles with the /usr/local/bin/install-sampledata script

I replaced the last line by this one:
mysql -h $MYSQL_HOST -u $MYSQL_USER -p $MYSQL_DATABASE < magento-sample-data-1.9.1.0/magento_sample_data_for_1.9.1.0.sql

Works fine, thanks.

bennypowers
a year ago

I'm trying to use this image with docker-machine to create a local magento installation on a mac, with htdocs exposed in my mac's project directory.

This is as far as I've gotten:

#docker-compose.yml
web:
  image: alexcheng/magento
  ports:
    - "80:80"
  links:
    - mysql
  env_file:
    - env
  volumes:
    - /var/www:/var/www
mysql:
  image: mysql:5.6.23
  env_file:
    - env

commands (using fish shell):

docker-machine create magento
eval (docker-machine env magento)
docker-machine stop magento
VBoxManage sharedfolder add magento-machine --name www --hostpath ~/web/magento-machine --automount
docker-machine start magento
docker-machine ssh magento

mkdir -p /var/www
sudo mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` www /var/www
exit

docker exec -it magentomachine_web_1 install-sampledata
docker exec -it magentomachine_web_1 install-magento

this works to expose /var/www on the magento machine to my project directory. However, this folder is not docker's /var/www but the machine's, so the real htdocs is something like

/mnt/sda1/var/lib/docker/aufs/diff/1d17cf805c6925dead7d0fd1ba432d1b27f50a5a9240f585949aac6fad633790/var/www

How can I run this image in docker-machine while exposing /var/www to my host machine?

ysilvela
a year ago

You need to put the internal docker IP of the web image when you setup Magento database. Other thing is that you need to put the root user in the connection

israelguido
a year ago

@ysilvela I have same problem, could explain better how to solve?

ysilvela
a year ago

Solved. You need to put the internal IP of the docker and root user

ysilvela
a year ago

Same error when running the install wizard. Error when connecting with database.

peterbata
a year ago

Why am I getting a Database connection error when running the install wizard

itrion
2 years ago

Hello all,

Where can I found a list of all the valid values for the
MAGENTO_LOCALE,
MAGENTO_TIMEZONE,
MAGENTO_DEFAULT_CURRENCY?

alexcheng
2 years ago

It seems that direct download link in Magento site won't be back soon, so I switched to use OpenMage's magento mirror