Category Archives: Docker

Docker Configuration for development env on Mac

Recently, my computer meets a problem; it already shuts down automatically. I already influences my normal development work. I went to apple store and then they checked everything. They said nothing wrong with hardware, maybe something wrong with software. They suggested me to refresh everything and recover back to empty operating system. It is really pain thing for me. Backup all documents, images and videos cost me 5 hours. This is ok, because I only need copy them back. But all applications and development env are gone. In fact, applications are also ok, since I can re-install them back. The worst thing is for the development env. I need to re-install and re-configure. So in order to avoid this worst thing happens again, I decide to use Docker to re-config my development env. If in the future, the problem happens again or I need to switch to another new device to work, it is more easily for me and helps me to shorten the transformation time. So let’s do it!

My final target development env

Nginx: load balance, file system, web server
Play framework: web architecture
Git : version control
Mysql: data storage
Gulp and sass: front-end css development

How to touch Docker

Step1: Download and Install

Go to here to download and install. Now there is another method which also can help you install docker, named Docker Toolbox.

Step2: Open your terminal

$ boot2docker init // it will create a Docker VM
$ boot2docker start // It will start Docker VM
$ boot2docker start -m=512 //If your memory size is less than 4G, you'd better manually figure out VM size
$ boot2docker ip
$ boot2docker ssh (Default password: tcuser) // it will enter Docker VM
$ exit // it will quit Docker VM
$ boot2docker stop // it will stop Docker

Step3: Some useful Docker commands in VM

$ docker search centos // It will help you to search one image
$ docker pull centos // It will help you to download one image
$ docker images // it will list all images which you have
$ docker ps // it will show all running containers
$ docker ps -a // it will show all containers
$ docker rm // it will remove container
$ docker rmi // it will remove image
$ docker rm `docker ps -a -q` // it will remove all containers
$ docker history image_name // list image's history
$ docker info // get docker info

Step4: Start your own image

Step4.1 Enter into a new container

$ docker search ubuntu
$ docker pull ubuntu
$ docker run -i -t ubuntu // -i: sync container's stdin, -t: sync container's output, -d: deamon and uses backend to start this container

4.2 Start to install everything which you need

$ apt-get install nginx
$ apt-get install git
$ apt-get install vim
$ apt-get update
$ apt-get install software-properties-common python-software-properties // for JAVA
$ add-apt-repository ppa:webupd8team/java // for JAVA
$ apt-get update // for JAVA
$ apt-get install oracle-java8-installer // for JAVA
$ java -version // check java
$ wget // for Typesafe
$ apt-get install unzip // for unzip
$ unzip // for Typesafe (I have problem on the newest version 1.3.5 when unzip; but it is ok for 1.2.12. So here I still use 1.2.12)
$ rm // for Typesafe
$ vi ~/.bashrc // add PATH=$PATH:/activator-1.2.12
$ source ~/.bashrc // activate bashrc
$ echo $PATH // check it
$ activator -help // check typesafe
$ apt-get install mysql-server mysql-client // for MySQL (during this process, you need to set your MySQL password)
$ mysql -V // check mysql

4.3 Submit your container

$ docker ps -l
$ docker commit -m "add nginx from ubuntu:latest" -a "haimei" 98710810b120 haimei/ubuntu-nginx:v1 // -m: add description; -a: figure author; 98710810b120: container's ID; haimei/ubuntu-nginx:v1 figures imageName,repositoryName and tagName

4.4 Connect between different containers

Step5: Publish to Docker Hub

$ docker login // input your info when you already signup on docker hub
$ docker push haimeili/ubuntu-nginx:v1

Step5: Fix bugs

“no space left on device”

If you’re using Boot2Docker with a large number of images, or the images you’re working with are very large, your pulls might start falling with “no space left on device” errors when the Boot2Docker volume fills up.

Here are some steps you need to do to fix it.

$ boot2docker config
$ boot2docker config > ~/.boot2docker/profile
$ vi ~/.boot2docker/profile // modify: DiskSize = 50000
$ boot2docker poweroff
$ boot2docker destroy
$ boot2docker init
$ boot2docker up