Docker is a command line tool to help you to create some virtual environment like a real one.

If you need to create a virtual unbuntu environment with a jenkins, tomcat, oracle ldap, oracledb and whatever you want running on any machine like linux, mac os and soon on windows, this is what you need.

It works with images/repositories and container and can be easily shared and be installed once you made the basic configuration of your environment.

Let’s begin introduction of this powerful tool :

Under MacOS X :

You need to install boot2docker in order to run docker.

Boot2docker commands :

boot2docker status
boot2docker start
boot2docker stop
boot2docker version
boot2docker ip          (show the ip of boot2docker virtual machine)
boot2docker shellinit   (show env var + info)

Docker commands :

docker version
docker ps          (show recent/active docker containers)
docker ps -a       (show all docker containers)
docker images      (show all docker images/repositories)
docker rm CPID     (delete a container)
docker rmi IPID    (delete an image, containers which use the image avoid the deletion)
docker run [-itdpP]  
(run a container from an image, if it doesn't exist locally, it will search on Docker Hub)
docker port CPID   (show the port mapping of a container)
docker logs CPID   (show logs of the container)
docker stop CPID   (stop the container)

Example : Running the hello world container

docker run hello-world       
(download an image from docker hub and launch a container to prompt hello world then exit)
docker rm hello-world-CONTAINTER_PID  
(this will delete the created container which doesn't run anymore)
docker rmi hello-world-IMAGE_PID        
(this will delete the created image which we doesn't need anymore)

Example : Running a nginx server

docker run -d -P --name kiki nginx  (This will launch a background nginx server image from docker hub and name it kiki. the ports of the container is randomly created then mapped with the -P option)
docker run -d -p 8089:80 -p 32770:443 --name kiki nginx  (as before but the ports mapping are setted manually with the -p option, first port is the port on virtual machine to set, the 2nd one is the nginx port server)
boot2docker ip
will give you the ip of the virtual machine
Go to the address : http://virtualMachineIP:8089

Connecting in bash on a container :

docker exec -it CPID bash

Managing images and container :

docker commit <container_id> name   (allow to persist an image from a container)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s