Introduction
Docker is a simple , faster VM like solution for developer to build lab
environment quickly , also publish product in docker image is a easy way
for customer test .
Note :
All below steps and experience was based on Windows platform .
1. Installation
get the windows installer and related doc from below url link:
https://docs.docker.com/installation/windows/
This installs Docker's management console program
Boot2Docker.
1.1 trobule shooting
mostly the installation should be successful , but in my case still encounter some issues.
The tips you may need to take care .
1) Make sure the hardware virturalization has turn on your pc bios .
Docker vm need the VT technology to bring on their service , if VT turn off , boot2docker would not start up .
2) Make sure docker vm in virtualbox network was mapping to adapter #1.
If you have install and uninstall virtualbox few times , there will be more than one virtual interface in network ,
then after docker installed , it will using other interface not #1 , in this case , boot2docker will got error while starting .
2. Launch operate console
Actually docker using the git console for operation .
Click the
Boot2Docker icon to see the following
All docker shell command executed at below interface .
3. Start up and tutorial
The first time using docker , you can reference below starter guide .
https://docs.docker.com/articles/basics/#starting-a-long-running-worker-process
And also below doc has clearly showing how to use docker .
https://serversforhackers.com/getting-started-with-docker
4. My use case
I will show you how I start a empty centos 6.6 image then build a cherrypy test environment .
4.1 Pull a clean image from official site
docker hub has shared multiple linux OS , on https://hub.docker.com/
and the pull command as : (a os name centos , and the tag is 6.6 , searched on docker hub.)
# docker pull <name>:<tag>
docker pull centos:6.6
check the image has save .
docker images
4.2 Mount host directory and into interactive mode to image OS
There are few ways to put your file into docker image OS , the direct way is to mount host directory then point to container path .
as below command .
#ex: mounting host director c:\temp to container's /home/mount .
#below command will run into centos container with interactive mode and mount host directory to container pointing path.
docker run -v //c/temp:/home/mount:rw -it centos:6.6 bash
note: It's been observed that c:/temp could not be mounted in some cases. If it happens, try mounting C:/Users/
. For example:
docker run -v //c/Users/Well:/home/mount:rw -it centos:6.6 bash
Successful launching turns your Docker Management Console into a bash shell of the centos container you just started.
When into the interactive mode in centos container , you can use shell command in container .
For example ls /home/mount to see mounted files.
in my case , I install below applications .
yum -y install gcc
yum -y install vim
# install the cherrypy from mount path
cp /home/mount/cherrypy-3.7.tar.gz /tmp
tar -zxvpf cherrypy-3.7.tar.gz
cd cherrypy-3.7
./setup.py install
4.3 Commit the last modified container to image
Like git , every time you run the image to do some progress, docker
will create a container to save the status , but not commit to the image
,
this means the next time you run the image or save the image , the last status does not include inside it .
So you need to decide which container would committed in image , in my case , I use last one container to commit in image .
Tips : in the container interactive mode , if you just want to stop not exit the status , you can input CRLT + p , CRLT + q ,
then back to main console , input "docker ps"
to see the current container id , then input "docker exec -it
<container id> bash" to go back the current container interactive
mode .
In my case , I stop my current container . and input following command .
#list the current container id
docker ps
#get the container id and commit to pointing image name
docker commit <container id> centos:6.6
#or if you want to save a new image. you can input new image name.
docker commit <container id> new_name
4.4 Publish and test the UI web service
Docker can mapping port to container , in my case , web service is 8080 port , the command as below .
# parameter -d is daemon mode .
docker run -d -p 8080:8080 centos:6.6 /home/ddna_api/index.py -D FOREGROUND
And use below command to see the docker host ip address.
boot2docker ip
4.5 How to save your image file .
If you want to save your working image then share to others , be sure you have commit the last container ,
and input below command .
#ex: if you want to save at c:\temp\ , named test_image.tar
docker save -o /c/temp/test_image.tar centos:6.6
5. Import the exist docker image for testing
if the image file placed at c:\temp , then open the boot2docer console , and input below command.
docker load -i /c/temp/web_service.tar
the image has loaded into docker , you can use step .4.4 to test the web service .
留言