# os with ssh
# images
FROM centos:6.10

RUN yum repolist

RUN echo "http://vault.centos.org/6.10/os/x86_64/" > /var/cache/yum/x86_64/6/base/mirrorlist.txt
RUN echo "http://vault.centos.org/6.10/extras/x86_64/" > /var/cache/yum/x86_64/6/extras/mirrorlist.txt
RUN echo "http://vault.centos.org/6.10/updates/x86_64/" > /var/cache/yum/x86_64/6/updates/mirrorlist.txt

# Update the system and install packages
RUN yum -y update && \
    yum install -y vim net-tools iputils wget tar curl glibc openssh-server mysql-server httpd \
    php php-mbstring php-pdo php-xml php-mysql

# Setting locale ko
RUN yum install -y glibc && \
    localedef -i ko_KR -f UTF-8 ko_KR.UTF-8 && \
    echo -e "# Setting Language(ko_KR.UTF-8)\nexport LANGUAGE=ko_KR.UTF-8\nexport LANG=ko_KR.UTF-8" >> /etc/profile

# Install OpenSSH Server
RUN mkdir /var/run/sshd && \
    echo 'root:!@#gds$%^' | chpasswd && \
    sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd && \
    echo "export VISIBLE=now" >> /etc/profile

# mySQL setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/my.cnf && \
    echo default-character-set=utf8 >> /etc/my.cnf && \
    echo lower_case_table_names=1 >> /etc/my.cnf && \
    echo default-time-zone='+9:00' >> /etc/my.cnf && \
    echo skip-character-set-client-handshake >> /etc/my.cnf

#apache install
RUN yum install -y httpd

# Copy configuration files and scripts
COPY httpd.conf sshd_config php.ini my.cnf /etc/
COPY start_service.sh setting.sql dump.sql /service_script/
RUN chmod +x /service_script/start_service.sh

# Expose port
EXPOSE 22 3306 80

# Run SSH, DB, APACHE
CMD ["/bin/bash", "/service_script/start_service.sh"]
