顯示具有 docker 標籤的文章。 顯示所有文章
顯示具有 docker 標籤的文章。 顯示所有文章

2023年3月28日 星期二

docker-compose.yml

docker-compose.yml


version: '2.2'

services:

  workstation:
    image: jeffwen0105/ansible_server:0.2
    hostname: workstation      
    privileged: true
    command: ['/sbin/init']
    volumes:
      - mydata:/home/student/playground
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.10   

  servera:
    image: jeffwen0105/ansible_server:0.2
    hostname: servera
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.11    

  serverb:
    image: jeffwen0105/ansible_server:0.2
    hostname: serverb
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.12    

  serverc:
    image: jeffwen0105/ansible_server:0.2
    hostname: serverc  
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.13

  serverd:
    image: jeffwen0105/ansible_server:0.2
    hostname: serverd
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.14

  servere:
    image: jeffwen0105/ansible_server:0.2
    hostname: servere
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.15

  serverf:
    image: jeffwen0105/ansible_server:0.2
    hostname: serverf
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.16

  serverg:
    image: jeffwen0105/ansible_server:0.2
    hostname: serverg
    privileged: true
    command: ['/sbin/init']
    extra_hosts:
      - "workstation.lab.example.com:10.10.10.10"
      - "servera.lab.example.com:10.10.10.11"
      - "serverb.lab.example.com:10.10.10.12"
      - "serverc.lab.example.com:10.10.10.13"
      - "serverd.lab.example.com:10.10.10.14"
      - "servere.lab.example.com:10.10.10.15"
      - "serverf.lab.example.com:10.10.10.16"
      - "serverg.lab.example.com:10.10.10.17"
    networks:
      ansible:
        ipv4_address: 10.10.10.17

networks:
  ansible:
    driver: bridge
    ipam:
      config:
        - subnet: 10.10.10.10/16
          gateway: 10.10.10.1

volumes:
  mydata:

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...