CheapWindowsHosting.com | In this post I’ll show you how you can quickly and easily setup a fast Joomla! site running in Docker, and using Memcached for caching. We’ll also be using Docker Compose to make managing the relationships between containers easier. Docker Compose makes the task of managing multiple Docker containers much easier than doing them individually. It also makes it easier if you want to develop this site on your local environment and later push it to a remote server with docker — although that’s a topic for another tutorial.
If you haven’t installed Docker on your machine yet, follow these instructions. The instructions for Ubuntu 14.04 (LTS) are below. Be sure to run them as root! If you already have Docker skip on to installing Docker Compose if you don’t already have it.
Install Docker on Ubuntu 14.04 LTS apt-get update apt-get install apt-transport-https ca-certificates apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list apt-get update apt-get install linux-image-extra-$(uname -r) apparmor docker-engine service docker start
Next install docker compose:
curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` >> /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose -v
You should see docker-compose output its version information. Something like:
docker-compose version 1.6.2, build 4d72027.
Next up we need to create the docker compose files and get the Joomla files ready to use:
Create Project Directory
mkdir -p ./mysite/website_source ./mysite/mysql cd mysite
Next create a
vim Dockerfile) that tells Docker to base your webserver code off of a PHP5 image, and include your source code.
Dockerfile FROM php:5-fpm # Install dependencies RUN apt-get update -y && apt-get install -y php5-json php5-xmlrpc libxml2-dev php5-common zlib1g-dev libmemcached-dev # Install mysqli extension RUN docker-php-ext-install mysqli # Install memcache extension RUN pecl install memcache && docker-php-ext-enable memcache # Add sources to image ADD ./website_source /site
And then create the
docker-compose.yml file (e.g.
vim docker-compose.yml). The docker-compose file lays out how your website is structured. It says that your site is composed of three services:
web which is an Apache/PHP image with your source code baked in,
db which is the MySQL database, and
cache which is the memcached image. It also tells docker how to connect these docker containers so that they can communicate with each other. Lastly, it tells docker to bind port 80 to the
web container. Lastly, the mysql container will mount the
mysql directory on the host and place the database files there. This way if the container is removed or anything you don’t lose your database.
docker-compose.yml version: '2' services: web: build: . command: php -S 0.0.0.0:80 -t /site ports: - "80:80" depends_on: - db - cache volumes: - ./website_source:/site db: image: orchardup/mysql environment: MYSQL_DATABASE: joomla MYSQL_ROOT_PASSWORD: my_secret_pass volumes: - ./mysql:/var/lib/mysql cache: image: memcached
By sure to replace
my_secret_pass with a secure password for the mysql user!
Now that you have a
docker-compose.yml you just need to get the sources for Joomla and install them:
Download and Install Joomla! wget https://github.com/joomla/joomla-cms/releases/download/3.4.8/Joomla_3.4.8-Stable-Full_Package.zip unzip Joomla*.zip -d ./website_source mv ./website_source/htaccess.txt ./website_source/.htaccess mv ./website_source/robots.txt.dist ./website_source/robots.txt
Note that if you don’t have
unzip installed you can install it by running
apt-get install unzip.
Now that you have everything setup its time to test everything by building and running the docker containers. This is accomplished with
docker-compose build docker-compose up
This will run the whole application in the foreground of your terminal. Go to
http://localhost:80 and complete the Joomla Installer! You’ll use the mysql username and password you specified in your docker-compose.yml file. The mysql host is also specified in the
docker-compose.yml file as the name of the database service. In our case, this is
db. Once you’re finished you can use
CTRL+C to stop the containers.
Now that your Joomla site is running under docker it’s time to connect it to the memcached server to make sure that things stay speedy!
To enable memcached edit
website_sources/configuration.php and replace
public $caching = '0'; public $cache_handler = 'file';
public $caching = '2'; public $cache_handler = 'memcache'; public $memcache_server_host = 'cache'; public $memcache_server_port = '11211'
Add your changes to the container image with
docker-compose build and then run
docker-compose up, log into the Joomla administration page and go to “Global Configuration” -> “System”. You can tweak the settings under “Cache Settings” or leave them as they are.
The last step in setting up a web application with docker is to have the web server started when the server starts.
Create the file
/etc/init/mydockersite.conf with the contents:
/etc/init/mydockersite.conf description "Website Docker Compose" author "MichaelBlouin" start on filesystem and started docker stop on runlevel [!2345] respawn script /usr/local/bin/docker-compose -f /var/www/mysite/docker-compose.yml up end script
Be sure to replace
/var/www/mysite/docker-compose.yml with the full path to your
Save the file and run the following to register the service, and to start it:
initctl reload-configuration service mydockersite start
And there you go! You can view logs for your service by running
docker-compose logs while in the same directory as your
docker-compose.yml or by reading the logfile at
CheapWindowsHosting.com | Best and cheap Docker hosting. Docker’s commercial solutions provide an out of the box CaaS environment that gives IT Ops teams security and control over their environment, while enabling developers to build applications in a self service way. With a clear separation of concerns and robust tooling, organizations are able to innovate faster, reduce costs and ensure security.
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
Containers running on a single machine share the same operating system kernel; they start instantly and use less RAM. Images are constructed from layered filesystems and share common files, making disk usage and image downloads much more efficient.
Docker containers are based on open standards, enabling containers to run on all major Linux distributions and on Microsoft Windows — and on top of any infrastructure.
Containers isolate applications from one another and the underlying infrastructure, while providing an added layer of protection for the application.