# M/Monit 部屬教程

# 建立 Dockerfile

FROM ubuntu:20.04
RUN apt update && \
	apt-get install -y wget curl tar
RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Taipei apt-get -y install tzdata
RUN TZ=Asia/Taipei \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone \
&& dpkg-reconfigure -f noninteractive tzdata 
WORKDIR /app
RUN wget https://mmonit.com/dist/mmonit-3.7.12-linux-x64.tar.gz && \
	tar zxvf mmonit-3.7.12-linux-x64.tar.gz && \
	rm mmonit-3.7.12-linux-x64.tar.gz && \
	mv mmonit-3.7.12 mmonit
RUN sed -i 's/port="8080"/port="80"/' /app/mmonit/conf/server.xml
RUN touch /app/mmonit/logs/error.log
COPY ./start.sh .
RUN chmod +x start.sh 
CMD ["./start.sh"]

# 建立 start.sh

start.sh
#!/bin/bash
/app/mmonit/bin/mmonit &
tail -f /app/mmonit/logs/error.log

# 建立 docker-compose.yml

version: "3.9"
services:
    mmonit:
        build: .
        stdin_open: true
        tty: true
        image: mmonit
        container_name: mmonit
        restart: always
        networks:
            default:
                ipv4_address: "172.20.0.9"
networks:
  default:
    name: dockercompose_static
    external: true

# 編譯及啟動容器

docker-compose up -d --build