2023年3月26日 星期日

自制LAB Docker image

 

Dockerfile 寫法

https://philipzheng.gitbook.io/docker_practice/dockerfile/instructions#user

藍色可換你想要用的OS,紅色為出處,下面有標記來源端

Dockerfile

FROM rockylinux:8.7.20230215


LABEL maintainer="MikeSCHsieh <cc.vbhsieh@gmail.com>"
LABEL maintainer="website : https://jeffwen0105.com/"
RUN yum install -y vim  net-tools telnet sudo passwd  openssh-* python3-dev* curl wget bash-completion openssl epel-release
RUN yum install ansible -y
RUN ssh-keygen -A
# RUN sed 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config > /etc/ssh/sshd_config
RUN echo  redhat | passwd  --stdin root
RUN useradd --create-home --shell /bin/bash  devops
RUN echo  redhat | passwd  --stdin devops
RUN echo 'devops ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
RUN ssh-keygen -q  -N  "" -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >  ~/.ssh/authorized_keys
RUN useradd --create-home --shell /bin/bash  student
RUN echo  redhat | passwd  --stdin student
RUN echo 'student ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
USER devops
RUN ssh-keygen -q  -N  "" -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >  ~/.ssh/authorized_keys
USER student
RUN ssh-keygen -q  -N  "" -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >  ~/.ssh/authorized_keys  && mkdir -p ~/playground
RUN echo -e 'autocmd FileType yaml setlocal ai ts=2 sw=2 et\n:set cursorcolumn' > /home/student/.vimrc
COPY src/example.tar.gz  /tmp/.
COPY src/labs.tar.gz /tmp/.
RUN tar -C /home/student/playground/  -zxvf /tmp/example.tar.gz
RUN tar -C /home/student/playground/  -zxvf /tmp/labs.tar.gz
USER root
RUN echo -e  "Host * \n \tStrictHostKeyChecking no" >> /etc/ssh/ssh_config
RUN cat /home/student/.ssh/id_rsa.pub >>  /home/devops/.ssh/authorized_keys && cat /home/devops/.ssh/id_rsa.pub >>  /home/student/.ssh/authorized_keys
RUN chown -R student:student /home/student/ && chown -R devops:devops /home/devops
EXPOSE 22

# CMD ["/usr/sbin/sshd","-D"]


結合指令:

這個會比較大一點。

podman build -t test .    


buildah build -t test 

出處:

https://github.com/JeffWen0105/Ansible

沒有留言:

RHEL install EPEL

  https://www.linuxtechi.com/install-epel-repo-on-rhel-system/ EPEL dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest...