Giter Site home page Giter Site logo

docker-drupal's Introduction

Drupal development with Docker

Build Status

Quick and easy to use Docker container for your local Drupal development. It contains a LAMP stack and an SSH server, along with an up to date version of Drush. It is based on Debian Stretch.

Summary

This image contains:

  • Apache 2.4
  • MariaDB 10.1
  • PHP 7.0
  • Drush 8
  • The latest release of Drupal Console (for 8 and 8.*.* tags)
  • Drupal 7 or 8 (depending on tag)
  • Composer
  • PHPMyAdmin
  • Blackfire

When launching, the container will contain a fully-installed, ready to use Drupal site.

Passwords

  • Drupal: admin:admin
  • MySQL: root: (no password); drupal:drupal
  • SSH: drupal:drupal (root:root)

Exposed ports

  • 80 and 443 (Apache)
  • 22 (SSH)
  • 3306 (MySQL)

Environment variables

If you wish to enable Blackfire for profiling, set the following environment variables:

  • BLACKFIREIO_SERVER_ID: Your Blackfire server ID
  • BLACKFIREIO_SERVER_TOKEN: Your Blackfire server token

Tutorial

You can read more about this image here.

Installation

Github

Clone the repository locally and build it:

git clone https://github.com/wadmiraal/docker-drupal.git
cd docker-drupal
docker build -t yourname/drupal .

Notice that there are several branches. The master branch always refers to the current recommended major Drupal version (version 8 at the time of writing). Other branches, like 7.x, reflect prior versions.

Docker repository

Get the image:

docker pull wadmiraal/drupal

Tags

You can specify the specific Drupal version you want, like 7.41 or 8.0.0. For example:

docker pull wadmiraal/drupal:7.41

You can also use the latest Drupal version of any major release branch by omitting the minor (and patch) version information:

docker pull wadmiraal/drupal:7

Running it

For optimum usage, map some local directories to the container for easier development. I personally create at least a modules/ directory which will contain my custom modules. You can do the same for your themes.

The container exposes its 80 and 443 ports (Apache), its 3306 port (MySQL) and its 22 port (SSH). Make good use of this by forwarding your local ports. You should at least forward to port 80 (using -p local_port:80, like -p 8080:80). A good idea is to also forward port 22, so you can use Drush from your local machine using aliases, and directly execute commands inside the container, without attaching to it.

Here's an example just running the container and forwarding localhost:8080 and localhost:8022 to the container:

docker run -d -p 8080:80 -p 8022:22 -t wadmiraal/drupal

If you want to run in HTTPS, you can use:

    docker run -d -p 8443:443 -p 8022:22 -t wadmiraal/drupal

Writing code locally

Here's an example running the container, forwarding port 8080 like before, but also mounting Drupal's sites/all/modules/custom/ folder to my local modules/ folder. I can then start writing code on my local machine, directly in this folder, and it will be available inside the container:

docker run -d -p 8080:80 -v `pwd`/modules:/var/www/sites/all/modules/custom -t wadmiraal/drupal

Using Drush

Using Drush aliases, you can directly execute Drush commands locally and have them be executed inside the container. Create a new aliases file in your home directory and add the following:

# ~/.drush/docker.aliases.drushrc.php
<?php
$aliases['wadmiraal_drupal'] = array(
  'root' => '/var/www',
  'remote-user' => 'root',
  'remote-host' => 'localhost',
  'ssh-options' => '-p 8022', // Or any other port you specify when running the container
);

Next, if you do not wish to type the root password everytime you run a Drush command, copy the content of your local SSH public key (usually ~/.ssh/id_rsa.pub; read here on how to generate one if you don't have it). SSH into the running container:

# If you forwarded another port than 8022, change accordingly.
# Password is "root".
ssh root@localhost -p 8022

Once you're logged in, add the contents of your id_rsa.pub file to /root/.ssh/authorized_keys. Exit.

You should now be able to call:

drush @docker.wadmiraal_drupal cc all

This will clear the cache of your Drupal site. All other commands will function as well.

Using Drupal Console

Similarly to Drush, Drupal Console can also be run locally, and execute commands remotely. Create a new file called ~/.console/sites/docker.yml and add the following contents:

# ~/.console/sites/docker.yml
wadmiraal_drupal:
	root: /var/www
	host: localhost
	port: 8022 # Or any other port you specify when running the container
	user: root
	console: drupal

You can now call something like:

drupal --target=docker.wadmiraal_drupal module:download ctools 8.x-3.0-alpha19

You can find more information about Drupal Console in the official documentation.

Running tests

Note: did you know you can now run tests very quickly without having to maintain a local Drupal instance? Check drupal-run-tests.sh for more information.

If you want to run tests, you may need to take some additional steps. Drupal's Simpletest will use cURL to simulate user interactions with a freshly installed site when running tests. This "virtual" site resides under http://localhost:[forwarded ip]. This gives issues, though, as the container uses port 80. By default, the container's virtual host will actually listen to any port, but you still need to tell Apache on which ports it should bind. By default, it will bind on 80 and 8080, so if you use the above examples, you can start running your tests straight away. But, if you choose to forward to a different port, you must add it to Apache's configuration and restart Apache. You can simply do the following:

# If you forwarded to another port than 8022, change accordingly.
# Password is "root".
ssh root@localhost -p 8022
# Change the port number accordingly. This example is if you forward
# to port 8081.
echo "Listen 8081" >> /etc/apache2/ports.conf
/etc/init.d/apache2 restart

Or, shorthand:

ssh root@localhost -p 8022 -C 'echo "Listen 8081" >> /etc/apache2/ports.conf && /etc/init.d/apache2 restart'

If you want to run tests from HTTPS, though, you will need to edit the VHost file /etc/apache2/sites-available/default-ssl.conf as well, and add your port to the list.

MySQL and PHPMyAdmin

PHPMyAdmin is available at /phpmyadmin. The MySQL port 3306 is exposed. The root account for MySQL is root (no password).

Blackfire

Blackfire is a free PHP profiling tool. It offers very detailed and comprehensive insight into your code. To use Blackfire, you must first register on the site. Once registered, you will get a server ID and a server token. You pass these to the container, and it will fire up Blackfire automatically.

Example:

docker run -it --rm -e BLACKFIREIO_SERVER_ID="[your id here]" -e BLACKFIREIO_SERVER_TOKEN="[your token here]" -p 8022:22 -p 8080:80 wadmiraal/drupal

You can now start profiling your application.

docker-drupal's People

Contributors

edurenye avatar mishac avatar theodorosploumis avatar wadmiraal 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

docker-drupal's Issues

Docker build broke

docker build -t corwin/drupal .

...
Step 46 : RUN /etc/init.d/mysql start && cd /var/www && drupal module:download admin_toolbar 8.x-1.10 && drupal module:install admin_toolbar && drupal module:install simpletest
---> Running in 1538aa394250
Starting MySQL database server: mysqld ..
Checking for tables which need an upgrade, are corrupt or were
not closed cleanly..

[WARNING] In order to list all of the available commands you should install drupal first.

[Drupal\Core\DependencyInjection\ContainerNotInitializedException]
\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.

module:download [--latest] [--] []...

The command '/bin/sh -c /etc/init.d/mysql start && cd /var/www && drupal module:download admin_toolbar 8.x-1.10 && drupal module:install admin_toolbar && drupal module:install simpletest' returned a non-zero code: 1

Using it on Windows

I can successfully run a docker and pull your docker. However, when navigating to http://localhost:80 on my WIndows 10, I just get a blank page:

docker run -d -p 8080:80 -t wadmiraal/drupal:7

I am using Docker Toolbox. Do you have any insights as to how get it working?

I can't login to ssh

Hi, i can't login to ssh with root:root.
From my local macosx:
ssh root@localhost -p 32773 <- docker port
root@localhost's password:
Permission denied, please try again.
root@localhost's password:
Permission denied, please try again.
root@localhost's password:
root@localhost: Permission denied (publickey,password).

Persistent MySQL storage

Hi -- a great tutorial; works even on Windows!

However, I wonder what would you do if you wanted to make the database storage persistent. It is not very practical to have to import the database every time a container starts.

Docker not building

I'm seeing a few issues building the docker image as of yesterday. Seems that there are some packages that have changed recently as well as a composer issue? Just wondering if this is a known problem?

Can not log into container.

Hello! Before that, everything was working, now reinstalled the image and can not perform the input to the container across ssh, the same situation phpmyadmin " #1698 - Access denied for user 'root'@'localhost'"

Heating up

Hi Wouter

I am trying to use your docker-drupal on my MacBook Pro in a VirtualBox VM.
Works fine but in contrast to other containers my Mac tends to heat up like hell. My ventilator speeds up to almost maximum rpm after a few minutes. -> 95°C
I decreased the Execution Cap. of the boot2docker-vm to 40% but that gives me only a slight decrease in heat.
Do you experience the same behaviour on other installs?
I use VB 4.3.30 and boot2docker version 1.7.1, build 786b29d
I run Osx Yosemite 10.10.4 with 2,6GHz Intel Core i5 and 8 GB of RAM DDR3

Any suggestion?

Kind regards
Erwin

UPDATE

---> I think I found the source of the heat... I ran the docker via Kitematic, which I thought would be not much more than a gui, but in fact it does much more. When I run your docker directly in boot2docker, everything runs fine.
--> I also looked at the Mac-Activity-monitor who indicated that it was the 'electron-helper' proces taking insanely much processor time... I noticed on their community page the issue is known.
So: problem 'solved' at least I found a way around it.

drush ssh password

Hello, I can get puTTY to work up until password. Username I put in "root" but when I put in "root" for password, it says access denied. Any Ideas?

Drupal Console run error

Hi guys!

Running this command: drupal --target=docker.wadmiraal_drupal module:download ctools 8.x-3.0-alpha19

I receive the following errors:
PHP Warning: file_get_contents(): Filename cannot be empty in phar:///usr/local/bin/drupal/src/Helper/RemoteHelper.php on line 57
PHP Warning: file_get_contents(): Filename cannot be empty in phar:///usr/local/bin/drupal/src/Helper/RemoteHelper.php on line 62
Error with private key

I'm using the 1.0.0-beta3 version of Drupal Console

Could you help me with this issue?

docker drupal images 8.2.6 and 8.2.7

As reported by Bob:

Hi,

I very much appreciate the docker images you have provided. I am not a docker or drupal expert and I find the images are much easier to install that even docker-compose scripts.

However, I wanted to mention that it looks to me that the images for 8.2.6 and 8.2.7 lost the basic content types.

exceptionally slow on first page load

the site works ok once cached but first page loads (all of them) are very slow. first page load after login taking up to a minute.

im testing for first time and i havent mounted any volumes to host.

any suggestions to speed up initial page loads greatly appreciated.

HTTPS

Cannot get HTTPS to work
Everytime i redirect to a https site on my test site i get "SSL_ERROR_RX_RECORD_TOO_LONG"

why do you remove sh?

why do you do this

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

what's the point?

regards

can't pull drupal 8.5 image?

i can't find a working label to pull drupal 8.5.

docs suggest :8 label should do it, but thats pulling 8.4

any help appreciated

thanks

Run mounting host application??

The project looks great and thank you for posting code. I'm trying it for a Docker introduction and to run Drush on an existing site.

Is it possible pointing the image to existing host files and a mysql instance? My site is running on the host laptop IIS (but no drush). I'm seeing a "no site found" error when trying the project:

alpin@nick-hp MINGW64 /c/www/docker
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              c11854b254d2        About an hour ago   714.9 MB
docker-whale        latest              20fbd3f19fef        39 hours ago        274.2 MB
debian              wheezy              5e2a9df259d2        12 days ago         84.89 MB
....
wadmiraal/drupal    7.41                e72766b0c738        6 weeks ago         631.2 MB

alpin@nick-hp MINGW64 /c/www/docker
$ docker run -v $(pwd):/c/www/wyc.intranet.uw.edu/washyacht/ drush/drush cc all -y
No Drupal site found, only 'drush' cache was cleared.                  [warning]





PHP 5.4 not PHP 5.6

First of all...thanks for this it is a great start for me to use as my Drupal Dev environment. You mention in the Readme that it is using PHP 5.6 but in fact it is using 5.4. Can we get a release to correct that?

module install error on docker build

Looks like maybe an issue with the drupal console. I'm not familiar with it...

[InvalidArgumentException]
Command "module:install" is not defined.
Did you mean one of these?
site:install
module:download

The command '/bin/sh -c /etc/init.d/mysql start && cd /var/www && drupal module:download admin_toolbar 8.x-1.10 && drupal module:install admin_toolbar && drupal module:install simpletest' returned a non-zero code: 1

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.