Docker & Supervisord
Host and inside docker’ containers all use supervisord to control processes…
Host : CentOS 7
Install docker
Notice:1. Enable IP forwarding in Linux
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
$ sysctl -w net.ipv4.ip_forward=1
$ service docker restart
2. Cannot open directory .: Permission denied
$ chcon -Rt svirt_sandbox_file_t ./code/
Install supervisord
Notice:1. Supervisord.conf
default file is indeed /etc/supervisor.conf
2.Starting supervisor: Unlinking stale socket /var/run/supervisor.sock$ pip install meld3==0.6.7
find / -name supervisor.sock
unlink /…/supervisor.sock
$ unlink /var/run/supervisor.sockInstall golang
Notice:1. GOPATH=”….”
$ vi ~/.bashrc
Add
export GOPATH=”/home/Go”
A. Docker commands
1.Stop all containers
$ docker stop $(docker ps -a -q)2.Delete all containers
$ docker rm $(docker ps -a -q)- Delete all images
B. Build docker image
1. Prepare the Dockerfile
FROM centos:centos7
MAINTAINER Jeff Yang
ENV MAJOR_PATH /home/apps/IPMI/
ENV INSTALL_PATH /home/install/
ENV CONFIG_PATH /home/apps/DCMS/config/
RUN mkdir -p $MAJOR_PATH
RUN mkdir -p $CONFIG_PATH
RUN mkdir -p $INSTALL_PATH
### Install supervisord
#RUN yum update -y
#RUN yum -y install python-setuptools epel-release python-pip
#RUN easy_install supervisor
COPY setuptools-19.2.tar.gz $INSTALL_PATH
COPY meld3-0.6.5.tar.gz $INSTALL_PATH
COPY elementtree-1.2-20040618.tar.gz $INSTALL_PATH
COPY supervisor-3.1.3.tar.gz $INSTALL_PATH
COPY ipmiutil-2.9.6-1_rhel6.x86_64.rpm $INSTALL_PATH
RUN chmod 700 $INSTALL_PATH/setuptools-19.2.tar.gz && \
tar -zxvf $INSTALL_PATH/setuptools-19.2.tar.gz -C $INSTALL_PATH && \
cd $INSTALL_PATH/setuptools-19.2/ && \
python setup.py install
RUN chmod 700 $INSTALL_PATH/meld3-0.6.5.tar.gz && \
tar -zxvf $INSTALL_PATH/meld3-0.6.5.tar.gz -C $INSTALL_PATH && \
cd $INSTALL_PATH/meld3-0.6.5/ && \
python setup.py install
RUN chmod 700 $INSTALL_PATH/elementtree-1.2-20040618.tar.gz && \
tar -zxvf $INSTALL_PATH/elementtree-1.2-20040618.tar.gz -C $INSTALL_PATH && \
cd $INSTALL_PATH/elementtree-1.2-20040618/ && \
python setup.py install
RUN chmod 700 $INSTALL_PATH/supervisor-3.1.3.tar.gz && \
tar -zxvf $INSTALL_PATH/supervisor-3.1.3.tar.gz -C $INSTALL_PATH && \
cd $INSTALL_PATH/supervisor-3.1.3/ && \
python setup.py install
2. Build base image
$ docker build -t="code_icdc:v.01″ .
C. Backup image
1. Save image
$ docker save -o code_icdc_v01.tar code_icdc:v.01
2. Load image
$ sudo docker load –input code_icdc_v01.tar
OR
$ sudo docker load < code_icdc_v01.tar
D.
1. Build own program (ipmicdc)
$ go build ipmicdc.go ipmidocker.go
ipmidocker.go
1 | package main |
ipmicdc.go1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28func main() {
...
if os.Args[1] == "docker" { // docker version
numprocs := parserSupervisordConf(os.Args[0])
var err error
var sid IcdcDocker
sid.run( gPort, numprocs, gMaxHandleIPs)
if err != nil{
return
}
//--------------
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
sid.stop()
}()
//--------------
http.HandleFunc("/updateDB", sid.update)
var sic IcdcCmd
http.HandleFunc("/discover", sic.commReceiveDiscoverCommand)
http.HandleFunc("/lan", sic.commReceiveLanCommand)
http.ListenAndServe(":"+strconv.Itoa(gPort), nil)
}
...
}
2. Start.sh include docker‘s Supervisord.conf
Start.sh1
2
3
4
5#!/bin/sh
cp $ICDC_EXE_PATH/libs/libipmi.so /usr/lib/
ldconfig
cp $ICDC_EXE_PATH/s.conf /etc/supervisord.conf
/usr/bin/supervisord -c $ICDC_EXE_PATH/supervisord.conf -n
Supervisord.conf
…
[program:ipmicdc]
command=/home/apps/IPMI/ipmicdc %(process_num)d
process_name = %(process_num)d
numprocs=2
autostart=no
autorestart=yes
[program:ipmi]
command=/home/apps/IPMI/ipmicdc
autostart=yes
autorestart=yes
3. Start Host’s Supervisord
$ supervisord -c /home/jeff/icdc/supervisord_docker.conf -n
supervisord_docker.conf
[program:ipmi_docker]
command=./ipmicdc “docker”
autostart=yes
autorestart=true
stopwaitsecs=10
[root@localhost code]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f32ab2fe909e code_icdc:v.01 “/bin/bash” 44 seconds ago Up 41 seconds 0.0.0.0:31003->9080/tcp envTest1
2028a0d07072 code_icdc:v.01 “/bin/bash” 50 seconds ago Up 44 seconds 0.0.0.0:31002->9080/tcp envTest0