阿拉丁和灯

Thoughts, stories and ideas.



Docker demo

在阿里巴巴Dock分享中用到的命令。转载请注明出处。

0. 准备工作
Yum -y update
Pull所有image
准备同一个可用区的两台机器


1. Installation & Get Started & Ghost
Basic:
yum -y update 
yum -y install docker

docker -v
docker version
docker info

docker daemon &

ls -la /run


Ghost:
docker pull ghost
docker run --name some-ghost -p 8080:2368 -d ghost
http://ip:8080/


ps in host !
Docker history
Docker stats
Docker ps
Docker exec -it 
Docker attach
Netstat -nlp


2. Odoo
docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo123 --name db postgres 
docker run -d -p 8069:8069 --name odoo --link db:db odoo 
docker stats odoo db

3. Commit to images
docker stop odoo 
docker stop db 
docker commit odoo wuyijun/odoo 
docker commit db wuyijun/odoo_db 
docker save -o wuyijun_odoo.tar wuyijun/odoo
docker save -o wuyijun_odoo_db.tar wuyijun/odoo_db
docker inspect db 
#找到volume在host上的路径,保存该目录
tar -zcvf wuyijun_odoo_db_data.tar.gz -C /var/lib/…/ ./_data

#转到另外一台机器
docker rm odoo 
docker rm db 
docker load -i wuyijun_odoo.tar
docker load -i wuyijun_odoo_db.tar
tar -zxvf wuyijun_odoo_db_data.tar.gz

docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo123 -v /root/_data:/var/lib/postgresql/data --name db wuyijun/odoo_db 

docker run -d -p 8069:8069 --name odoo --link db:db wuyijun/odoo 


4. Docker file
vi Dockerfile
---
FROM ubuntu
MAINTAINER wuyijun
RUN echo "This is a test file" > /root/test.txt
CMD bash
---
docker build -t wuyijun/mycentos .
docker images
docker run -it -d --name mycentos1 wuyijun/mycentos

5. Compose
安装Docker Compose

wget https://github.com/docker/compose/releases/download/1.4.0/docker-compose-Linux-x86_64
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose  

运行
wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml  
docker-compose up &  
docker-compose down

6. Over Network
docker -H 0.0.0.0:2375 -H unix:///var/run/docker.sock -d &

export DOCKER_HOST="tcp://x.x.x.x:2375"
docker run -it centos /bin/bash


Jacob Wu