Category Archives: Coding

Configuring GD and Freetype on WordPress Docker Image

This applies to official WordPress image but can be used with PHP image also.

Create Dockerfile with following contents:

Build your image

Or you can use my image here.

 

Using WordPress and MySQL Docker Containers

I am just starting out on Docker and so far it’s been fun. Here I am going to show how I used Docker WordPress and MySQL containers.

Before I delve into the details, I want to tell you that I am going to be working on Windows using SSH on Docker VM. If you want to know how to do that see this post here.

So let’s start. Open SSH console. We are going to set up MySQL first.

On your landing directory, create a folder for MySQL. I am going to call it “mysql”

Change directory to the newly created folder

We are going to use official Docker MySQL image located here. Version: 5.7

Here’s the run command I am going to use. This will map port 3306 on the container to the VM thereby allowing me to access this MySQL instance using VM’s IP address and port 3306

But for ease of use I like to put the run command inside a Shell script I name as “run.sh”.

Create “run.sh” with following contents.

Make the script executable

Then, run the script.

Of course, I had already done this before therefore you see “Already exists” messages. If you are doing this for the first time, image should get downloaded which could take 2-3 minutes depending on your internet connection.

Now I can test this MySQL instance using any Windows DB Client. Use following settings with obviously the password you set. Note, I am using “root” as login. This is only for demonstration. Obviously, you will disable it in production.

Docker_DBeaver_MySQL

Once configured, you should be able to connect to the MySQL instance.

Docker_DBeaver_Connectr

So far so good, let’s set up WordPress now.

Like MySQL, we are going to use official WordPress image from here.

But first, let’s create folder for wordpress. I am going to call it, simply “wordpress”

Change directory…

Create run.sh

Here, we are linking previously created MyMySQL container with this going to be  created MyWordpress container. Also, we are going to map port 80 of the container to port 80 of the VM.

Execute script

Fire up a browser on your Windows machine and go to “http://192.168.99.100” and you should see WordPress Installation page!

Docker_Wordpress

Configuring Docker SSH on Bitvise on Windows

Docker on Windows has a lot to be desired. One thing I found uncomfortable to use is the Docker Shell on Windows. As of version 1.11.2, Docker uses MINGW64 extension to provide the UNIX Shell on Windows and even then it operates on the host, i.e. the Windows machine. If you know the current architecture, Docker runs on a Linux VM on top of Windows host. Therefore, what gets typed on Docker console is eventually passed to the VM. Through wonderful Docker documentation I figured I could actually SSH directly into the VM itself, and it’s very easy.

Docker Console on Windows
Docker Console on Windows

For my SSH I use Bitvise SSH client but these steps should apply to any other client such as Putty. Docker provides SSH private key which could be used by any client.

Open Bitvise Client Key Manager, and click on “Import”. Then Navigate to “c:\users\userid\.docker\machine\machines\default” and select “id_rsa” file. Import the file and note down the Location. It should be “Global n” where n=1,2,3 etc.

Docker_SSH_Key_File

Next open Bitvise SSH Client. Configure a profile with following details:

Docker_SSH_Options

Hit login and hopefully you will be logged in!

Docker_SSH

PyCharm on Windows and Docker

I have recently started using Python and Docker. As a novice, I wanted to configure PyCharm on Windows to use my Docker Python image. Here are couple of things I had to do to successfully accomplish this:

  • Your Project folder must be inside your Windows home folder, i.e. c:\users\user. If not, PyCharm will not be able to run your Python file

2016-06-16 21_02_45-Location

  • Next, ensure that Docker is selected as a “Remote Python Interpreter”. Obviously as a prerequisite you must install Docker and pull Python image. If done correctly, PyCharm should recognize the interpreter

2016-06-16 21_01_10-ConfigureDocker

With this you should be able to run your Python code directly against Docker image. Here’s a Hello World example I ran.

2016-06-16 21_04_28-HelloWorld - [C__Users_vikc0_Python_HelloWorld] - ..._hello_world.py - PyCharm 5

Installing Ruby on Rails on Fedora 16

I had somewhat of a hard time setting up a machine for my Ruby on Rails experiments but fortunately I was able to set up one after banging my head on the wall several times and with the help of several internet articles. So, here’s what I did:

1. First make sure you have apache, curl, git, mysql, sqlite and node.js installed (You might not need all of them). For this simply run the following command:

sudo yum install -y httpd, curl, git, mysql, mysql-server, sqlite, sqlite-devel, nodejs

If you can’t get nodejs installed, try the following command:

sudo yum install –nogpgcheck http://nodejs.tchol.org/repocfg/fedora/nodejs-stable-release.noarch.rpm

2. Next, install RVM (Ruby Version Manager)

curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm

Find other requirements for RVM, and install those too

rvm requirements

3. Install Ruby

rvm install 1.9.3

This will install both Ruby and Rubygems. If you get an error while installing rubygems, such as the following:
The requested url does not exist: ‘http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz’
Trying ftp:// URL instead.
curl: (6) Could not resolve host: production.cf.rubygems.org; Name or service not known
There was an error, please check /home/vikram/.rvm/log/ruby-1.9.2-p320/*.log
There has been an error while trying to fetch the source.
Halting the installation

You will have to install Rubygems separately. Otherwise skip to Step 5

Check Ruby version

ruby -v

4. Install Rubygems
Download http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz

wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz

Extract the file

tar -zxvf rubygems-1.8.24.tgz

Install

cd rubygems-1.8.24
ruby setup.rb

5. Set default Ruby version

rvm use 1.9.3 –default

6. Install Rails

gem install rails

This will take a moment

7. Check Rails version

rails -v

Fortunately, it worked for me! If you run into additional problems check the following websites:
RVM: https://rvm.io/
Node.js: http://nodejs.tchol.org/
Rails: http://rubyonrails.org/download
Gems: http://rubygems.org/pages/download

UPDATE: Fedora 17 has a Ruby 1.9.3 yum package. After you install that, install rails (Step 6)