Woopii Vyeolog

[vagrant] Centos7 기반의 DockerServer VM 생성 본문

Vagrant

[vagrant] Centos7 기반의 DockerServer VM 생성

WooPii 2022. 9. 6. 00:28

[참고] vagrant 설치

https://woopi1087.tistory.com/89

 

[Vagrant] Vagrant란?, Vagrant로 VirtualBox에 Centos7 설치

[참고] https://www.vagrantup.com/ Vagrant by HashiCorp Vagrant enables users to create and configure lightweight, reproducible, and portable development environments. www.vagrantup.com 1.Vagrant란?..

woopi1087.tistory.com


 

1. vagrantfile 작성

Vagrant.configure("2") do |config|
	# docker_server for docker
	config.vm.define "docker" do |cfg|	# 해당 설정의 고유 이름, 다른것과 중복되지 않도록 한다.			
		cfg.vm.box = "centos/7"			# 가져올 이미지의 명칭
		cfg.vm.provider "virtualbox" do |vb|	# 가상화 소프트웨어 종류
			vb.name = "docker_server"	# VM의 이름
			vb.cpus = 2			# VM의 CPU
			vb.memory = 4096		# VM의 Memory
			vb.gui = true
		end
		# VM설정 후 동봉된 Shell 실행
		cfg.vm.host_name = "server.docker.com"
		cfg.vm.network "private_network", ip: "192.168.55.10"
		# ssh_conf.sh를 실행해서 SSH 접속 관련 설정을 함
		cfg.vm.provision "shell", path: "ssh_conf.sh", privileged: true
		# add_hosts.sh을 실행해서 /etc/hosts에 도메인 설정을 함
		cfg.vm.provision "shell", path: "add_hosts.sh"
        	# docker_install.sh을 실행해서 docker를 설치한다.
		cfg.vm.provision "shell", path: "docker_install.sh", privileged: true
	end
end

 

 

2. ssh_conf.sh 

#/bin/bash
# ssh설정 파일 백업
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
# ssh 비밀번호 인증 허용
sed -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
# ssh 재시작
systemctl restart sshd

 

 

3. add_hosts.sh

#! /bin/bash
echo -n "127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
" > /etc/hosts
echo "192.168.55.10   server.docker.com server" >> /etc/hosts

 

 

4. docker_install.sh

#! /bin/bash
# Install editor and utilities
yum -y install vim net-tools bridge-utils

# set up the repository for docker install

yum install -y yum-utils 
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# Install Docker Engine
yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker

# setup enable docker permition to vagrant user
usermod -aG docker vagrant

 

 

5. 디렉토리 파일 구성

 

 

6. powershell 실행 후 'vagrant up' 명령어로 VM 구축

'Vagrant' 카테고리의 다른 글

[Vagrant] Vagrant란?, Vagrant로 VirtualBox에 Centos7 설치  (0) 2022.09.05
Comments