Gitlab CI runner and php docker image speed up

I was using Gitlab CI for a php project and the first line of .gitlab-ci.yml was this:

image: php:5.6

and in some lines below was this:

before_script:
    ##
    ## Install ssh-agent if not already installed, it is required by Docker.
    ## (change apt-get to yum if you use an RPM-based image)
    ##
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh

The problem is that php:5.6 image does not contain neither openssh-client nor git
so each time i was deploying something i had to wait for the container to update ubuntu packages and install git and openssh-client. A really slow process.

The solution was to create a php image that had these packages already installed.
I did this in Docker like this:

docker run -i -t php:5.6 /bin/bash
apt-get update
apt-get install openssh-client git

Before we exit the above php:5.6 container we open another shell and we get the docker ID of the running container.
Then we save an image kotsis/gitlabphp-5.6-fast of that container and we submit it in the docker hub.

docker ps #we get the docker ID of out   #auto to trexoume prin bgoume
docker commit DOCKER_ID kotsis/gitlabphp-5.6-fast
docker login
docker push kotsis/gitlabphp-5.6-fast:latest
docker logout

That’s it! Now inside .gitlab-ci.yml I put in the first line:

image: kotsis/gitlabphp-5.6-fast

No more installing packages during CI.

Cheers!