1. 程式人生 > >同一個docker映象,如何拉起多個docker container?

同一個docker映象,如何拉起多個docker container?

環境: centos7,zabbix3.0

關鍵步驟:

1. 安裝docker
yum install epel-release
yum install docker

2. 安裝docker-compose
sudo yum install -y python-pip
sudo pip install docker-compose

業務配置檔案:

LogFile=/tmp/zabbix_agentd.log
Server=10.1.1.1
ListenPort=10050
ServerActive=10.1.1.1:10051
AllowRoot=1

docker-compose配置檔案:


1個container時:

version: '1'
services:
  zabbix-agent000:      
    image: million12/zabbix-agent
    container_name: zabbix-agent
    restart: always
    network_mode: "bridge"
    ports:
      - "8000:10050"   
    volumes:
      - ./zabbix-agentd.conf:/etc/zabbix-agent/zabbix_agentd.conf
      - /proc:/data/proc
- /sys:/data/sys - /dev:/data/dev - /var/run/docker.sock:/var/run/docker.sock environment: - ZABBIX_SERVER=10.1.1.1 - CONFIG_FILE=/etc/zabbix-agent/zabbix_agentd.conf - HOST_METADATA=vir_sysquery - HOSTNAME=vir

2個container時:

version: '1'
services:
  zabbix-agent000:      
    image: million12/zabbix-agent
    container_name: zabbix-agent000
    restart: always
    network_mode: "bridge"
    ports:
      - "8000:10050"
volumes: - ./zabbix-agentd.conf:/etc/zabbix-agent/zabbix_agentd.conf:ro - /proc:/data/proc - /sys:/data/sys - /dev:/data/dev - /var/run/docker.sock:/var/run/docker.sock environment: - ZABBIX_SERVER=10.1.1.1 - CONFIG_FILE=/etc/zabbix-agent/zabbix_agentd.conf - HOST_METADATA=vir000_sysquery - HOSTNAME=vir000 zabbix-agent001: image: million12/zabbix-agent container_name: zabbix-agent001 restart: always network_mode: "bridge" ports: - "8001:10050" volumes: - ./zabbix-agentd.conf:/etc/zabbix-agent/zabbix_agentd.conf:ro - /proc:/data/proc - /sys:/data/sys - /dev:/data/dev - /var/run/docker.sock:/var/run/docker.sock environment: - ZABBIX_SERVER=10.1.1.1 - CONFIG_FILE=/etc/zabbix-agent/zabbix_agentd.conf - HOST_METADATA=vir001_sysquery - HOSTNAME=vir001

5. 執行命令
在docker-compose.yml 檔案所在的目錄執行

docker-compose up -d

如果要檢視啟動詳情,使用 docker-compose up 命令

至此,在docker所在的伺服器應該能夠看到有2個docker映象啟動。zabbix_server上也能看到有2個zabix_agent連線成功

FAQ:
問題:
起大批量的docker時,可能會出現以下問題:
ERROR: for zabbix-agent00103 UnixHTTPConnectionPool(host=’localhost’, port=None): Read timed out. (read timeout=60)
解決方法:
在起docker映象的伺服器上執行:
export COMPOSE_HTTP_TIMEOUT=3600