首先定义一个Dockerfile 安装虚拟机基础软件
vim Dockerfile
FROM centos:7
RUN yum install -y \
vim bash-com* openssh-clients openssh-server iproute cronie;\
yum group install -y "Development Tools";yum clean all;\
localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ENV LANG=zh_CN.UTF-8
使用docker-compose管理工具批量制作虚拟机
vim docker-compose.yml
version: '3.8'
services:
slb:
build: .
image: centos7-sshd
privileged: true #开启容器特权
command: /usr/sbin/init #linux的第一个进程
hostname: slb
container_name: slb
networks:
xiaochou:
tomcat1:
image: centos7-sshd
container_name: tomcat1
privileged: true
command: /usr/sbin/init
hostname: tomcat1
networks:
xiaochou:
tomcat2:
image: centos7-sshd
container_name: tomcat2
privileged: true
command: /usr/sbin/init
hostname: tomcat2
networks:
xiaochou:
mysql-master:
image: centos7-sshd
container_name: mysql-master
privileged: true
command: /usr/sbin/init
hostname: mysql-master
networks:
xiaochou:
mysql-slave:
image: centos7-sshd
container_name: mysql-slave
privileged: true
command: /usr/sbin/init
hostname: mysql-slave
networks:
xiaochou:
ansible:
image: centos7-sshd
container_name: ansible
privileged: true
command: /usr/sbin/init
hostname: ansible
networks:
xiaochou:
networks:
xiaochou: