The official Hypernode Docker image for Magento development is now available. This image can be used to set up a fast and easy local development environment for Hypernode, or as a build machine in a CI environment representative of the production environment. The image contains the exact same packages and configuration as a real Hypernode except for some Docker specific tweaks. By testing and developing against this image you can be sure that when you deploy to a Hypernode in production there will be no surprises because of different software versions or configurations.

Interested in a case study? Read this article about the Hypernode docker of one of our partners!

About the Hypernode Docker image

We build this image multiple times a day (every time we do a release) by applying our configuration management on the phusion/baseimage-docker ‘fat’ container. By treating the Docker as a lightweight VM instead of as a vehicle for a single process we stay close to what an actual Hypernode actually looks like. No micro-services or a multi-container application, but a single instance with minimal network overhead and all batteries included.

The hypernode-docker image has SSH, PHP, NGINX, MySQL, Redis and Varnish. The biggest difference between a real Hypernode and this container is that this environment does not have an init system. While it is possible to run systemd within a Docker Container if the host is also runs systemd, we choose not to do so to achieve greater compatibility and user-friendliness.

Usage

First of all download the latest version of Docker for Windows or Mac from de Docker website (https://www.docker.com/get-started) and make sure to install Docker on your computer. If you are working with Linux you can find all the info to install Docker in their documentation Docker Docs: https://docs.docker.com/install

Start the Docker and logging in

Starting a container

Get the IP address

Log in to the container:

The password is insecure_docker_ssh_password, or use the pregenerated key.

Restarting services

Because systemctl is not available inside the container, the services are started by an init script on container startup. Note that because the systemd unit files are not parsed there could be a slight drift between what commandline flags the processes actually use in production compared to in this contanier.

To restart all services run:

If you only want to restart a specific service, inspect the restart_services.sh script and kill the screen for the service you want to restart. Then run the corresponding screen command to start the service again.

Starting the container

running the container on the foreground

To start the container in the foreground, run the following command:

You can now log in with SSH using the IP address seen in the output.

running the container on the background

To start the container in the background, run the following command:

The IP address of the container can then be found with:

You can view the logs with docker logs

Importing a Magento shop

  1. Add a hosts entry for the Docker

  1. Start an SSH agent and add your key

  1. Log in to the hypernode-docker container

  1. Double-check you are in the Docker environment and not the real Hypernode

5.

Run the hypernode-importer to import a shop from a real Hypernode

  1. Point your browser to the importer shop
    Go to http://hypernode.hypernode.local/

Switching PHP versions

Unlike the hypernode-vagrant you can not just run hypernode-switch-php to change the PHP version. Because there is no systemctl to manage the services other steps must be performed. To switch to a different PHP version run the following commands:

Adding keys to container

To create a Docker instance of hypernode-docker with your own keys, create a directory with your public key in it and a Dockerfile.

Then build the Docker with:

And once finished, start the Docker with:

Note: remember that you will also need to change the default app and root user passwords if you’re looking to create a secure environment.

Inspecting emails sent from the Docker

Like in the hypernode-vagrant project, all emails are caught and redirected to a MailHog instance. You can visit the mailhog web interface on port 8025. So for example, if the IP of your container is 172.17.0.2 you would be able to access MailHog on http://172.17.0.2:8025/.

Alternatively you could set up a hosts entry like so on the host (not in the Docker):

And then visit the MailHog instance on http://hypernode.hypernode.local:8025.

Installing Magento 1

Make sure you have a hosts entry set up:

Switch to a Magento 1 compatible PHP version

Log in to the container as the app user:

Remove any Magento 2 specific NGINX configuration:

Create a new database:

Install Magento with n98-magerun:

Run Docker on Mac

The Mac version of Docker works slightly different then the Linux version due to some network limitations on the Docker version for Mac. You should use port forwarding to connect to a container. So for example you could use:

Start a container:

Which will expose port 222 on the container and port 8080 on the localhost. In this example you should use the following command to connect to the container:

The password is ‘insecure_docker_ssh_password’.
From here on you could use the hypernode-importer to import a shop from a real Hypernode.

To see the container in your browser you should change the base-url to “http://127.0.0.1:8080/” and don’t forget to flush your cache afterwards:

Magento 1
How to change base-urls in Magento 1

Magento 2
How to change base-url in Magento 2

Varnish on Docker

By default Varnish is already enabled, but won’t work because the server is missing some configuration in order to work correctly. This isn’t implemented because there were earlier issues with Varnish on a Vagrant environment.

If you want to experiment with Varnish in your Docker environment you should overwrite the content of “/etc/nginx/outside.conf”, to do this you need to log in as root user.

Overwrite the content of “/etc/nginx/outside.conf” to the following:

Restart services
Restart the services after you changed the config file.

That’s it, Varnish should be working fine now! You can see the results when you enter ‘varnishhist’ in the CLI and click around in your webshop at http://127.0.0.1:8080/

53