从网上随便找了几个image,都是从svn下载的代码,根本跑不了,于是自己重新做了个,从git上拿的源码,只是build出来的image有点大,有时间再优化了

Dockerfile

FROM centos:centos7
MAINTAINER Ryan [email protected] ENV ZABBIX_VERSION=3.0.1 \
ZABBIX_SERVER=127.0.0.1 \
ZABBIX_SOURCE=zabbix-agent.${ZABBIX_VERSION}.tar.gz \
HOSTNAME=zabbix.agent \
HOST_METADATA=zabbix.agent \
CONFIG_FILE=/usr/local/etc/zabbix_agentd.conf RUN \
yum clean all && yum makecache && \
yum install --nogpgcheck -y automake gcc make iproute ADD ./${ZABBIX_SOURCE} /usr/local/src/ WORKDIR /usr/local/src RUN \
cd ./zabbix && \
./bootstrap.sh && \
./configure --enable-agent && \
make install RUN \
rpm -e --nodeps make gcc && \
yum remove -y automake && \
useradd -G wheel zabbix && \
rm -rf /usr/local/src/zabbix && \
yum clean all COPY ./bootstrap.sh / RUN \
chown -R zabbix:wheel /usr/local/etc/ USER zabbix EXPOSE 10050 ENTRYPOINT ["/bootstrap.sh"]

bootstrap.sh

#!/bin/sh
set -eu
export TERM=xterm # Bash Colors
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
white=`tput setaf 7`
bold=`tput bold`
reset=`tput sgr0`
separator=$(echo && printf '=%.0s' {1..100} && echo)
# Logging Finctions
log() {
if [[ "$@" ]]; then echo "${bold}${green}[LOG `date +'%T'`]${reset} $@"; else echo; fi
} ### Update config file based on environment variables
update_config() {
log "Updating configuration file..."
if [ ! -z "$ZABBIX_SERVER" ]; then
log "Changing Zabbix Server IP to ${bold}${white}${ZABBIX_SERVER}${reset}"
sed -i 's/^[# ]*Server=.*$/Server='$ZABBIX_SERVER'/g' ${TARGET_CONFIG_FILE}
fi
if [ ! -z "$HOSTNAME" ]; then
log "Changing Zabbix Hostname to ${bold}${white}${HOSTNAME}${reset}."
sed -i 's/^[# ]*Hostname=.*$/Hostname='$HOSTNAME'/g' ${TARGET_CONFIG_FILE}
fi
if [ ! -z "$HOST_METADATA" ]; then
log "Changing Zabbix Host Metadata to ${bold}${white}${HOST_METADATA}${reset}."
sed -i 's/^[# ]*HostMetadata=.*$/HostMetadata='$HOST_METADATA'/g' ${TARGET_CONFIG_FILE}
fi
log "Config updated"
}
print_config() {
log "Current Zabbix Agent config:"
printf '=%.0s' {1..100} && echo
cat ${TARGET_CONFIG_FILE}
echo ""
printf '=%.0s' {1..100} && echo
}
start() {
log "Starting Zabbix Agent using configuration file: ${TARGET_CONFIG_FILE}"
print_config
zabbix_agentd -f -c ${TARGET_CONFIG_FILE}
} # Use the default config file if not set by an environment variable
if [ -z "$CONFIG_FILE" ]; then
SRC_CONFIG_FILE="/usr/local/etc/zabbix_agentd.conf"
else
SRC_CONFIG_FILE="$CONFIG_FILE"
fi # This is the actual config file used, containing changes implied by environment variables
TARGET_CONFIG_FILE=$(mktemp)
log "Loading config: ${SRC_CONFIG_FILE}"
cp "$SRC_CONFIG_FILE" "$TARGET_CONFIG_FILE" update_config
start

  

  

05-11 22:22