# base가 될 이미지
FROM httpd
#아래 작업들을 수행할 계정 (apt 등은 root 권한이 필요하다)
USER root
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Asia/Seoul
# ssh server 설치
### Ubuntu
RUN apt-get update &&\
apt-get install -y openssh-server &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN mkdir /var/run/sshd
RUN echo 'root:startx' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/#X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config
RUN echo "export VISIBLE=now" >> /etc/profile
# 편의상 필요한 패키지 설치
### Ubuntu
RUN apt-get update &&\
apt-get install -y vim vi htop tcpdump net-tools curl &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# 사용자 추가
RUN useradd haedong -G sudo -m -d /home/haedong -s /bin/bash
RUN echo 'haedong:startx'| chpasswd
RUN echo "ls='ls --color=auto'" >> ~/.bash_profile
RUN echo "ll='ls -lha" >> ~/.bash_profile
RUN mkdir /var/run/sshd
# 외부로 연결할 포트
EXPOSE 22 80
# 서비스 시작을 위한 스크립트
RUN mkdir -p /root/scripts
COPY ssh_start.sh /root/scripts/ssh_start.sh
COPY httpd_start.sh /root/scripts/httpd_start.sh
COPY wrapper.sh /root/scripts/wrapper.sh
CMD /root/scripts/wrapper.sh
ssh_start.sh
#!/bin/bash
/usr/sbin/sshd -D
ssh_start.sh
#!/bin/bash
/usr/local/apache2/bin/httpd -DFOREGROUND
#!/bin/bash
# turn on bash's job control
set -m
/ssh_start.sh &
/httpd_start.sh &
fg %1
# base가 될 이미지
FROM httpd
아래 작업들을 수행할 계정 (apt 등은 root 권한이 필요하다)
USER root
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Asia/Seoul
## 편의를 위해 기본적으로 필요한 것들
## 프록시를 사용하는 경우 apt-get 앞에 다음을 추가한다.
# RUN sudo https_proxy=PROXY_SERVER_HOST:PORT http_proxy=PROXY_SERVER_HOST:PORT
RUN apt-get update &&\
apt-get install -y procps curl vim git openssh-client telnet net-tools tcpdump top htop --no-install-recommends &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
### Alpine Linux
# RUN apk update &&\
# apk add procps curl vim git openssh-client net-tools tcpdump htop sudo ncurses --no-cache &&\
# rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
#### 여기부터 SSH
### Ubuntu
RUN apt-get update &&\
apt-get install -y openssh-server --no-install-recommends &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
### Alpine
RUN apk update &&\
apk add openssh openssh-server-pam --no-cache &&\
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
RUN mkdir /var/run/sshd
# root password 변경
RUN echo 'root:PASSWORDt' | chpasswd
# ssh 설정 변경
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&\
sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config &&\
ssh-keygen -A
RUN mkdir /root/.ssh
# label add
LABEL comment "util add"
# alias를 추가하고 싶은 경우
RUN echo "alias ll='ls -lha'" >> /home/haedong/.bashrc
# pip 패키지 인스톨
RUN https_proxy=http://PROXY_SERVER_HOST:PORT http_proxy=PROXY_SERVER_HOST:PORT pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install --no-cache-dir s3fs py4j pytz toml xgboost==1.5.1 lightgbm==3.3.1 scikit-learn==1.0.1 mlflow mlflow-skinny sqlalchemy alembic sqlparse tqdm boto3
# jupyterhub(z2zh)의 경우 설정된 home directory의 권한 부여
RUN chown -R jovyan /home/haedong
# docker build -t 이미지_이름:TAG dockerfile이_존재하는_경로
docker build -t haedongg.net/library/pyspark-notebook:v3.2.0-2021206 .
# image push
docker push haedongg.net/library/pyspark-notebook:v3.2.0-2021206
# tag를 명시적으로 지정할 경우 굳이 수행하지 않아도 된다.
docker image tag haedongg.net/library/pyspark-notebook:v3.2.0-2021206 haedongg.net/library/pyspark-notebook:latest
docker push haedongg.net/library/pyspark-notebook:latest