Build Ubuntu+Docker virtual machine on Mac

IaC
スポンサーリンク
スポンサーリンク

Introduction

During development, it may be necessary to prepare a development environment such as a DB server or Web server according to the situation at that time for various reasons such as testing the program or checking the phenomenon when a failure occurs.

In such a case, if you prepare a separate terminal and build a new environment, it will take time to search for a free terminal and build the environment.Also, the method of directly installing the server software etc. in the local development environment may make it difficult to repair when different versions cannot coexist or the environment is broken due to testing etc.

As a method of solving these problems, there is a method of constructing a virtual environment in the local development environment and freely constructing or destroying the environment in it.

Recently, even on Mac, you can easily build and destroy the environment using containers using Docker Desktop, but this time, build a virtual machine on Ubuntu 20.04 with VirtualBox + Vagrant and build the Docker environment on it. Build

We also make it as easy as possible to build and destroy environments using scripts.

The script used for execution is published on Github.I think that it can be used for test automation etc. by changing the script when building the virtual environment with Vagrant.

This page only describes the procedure for creating a Ubuntu+Docker virtual machine on Virtual Box using the virtual machine building script (vm-configure).

If you want to know what you are doing in the script, please refer to the link to the file related to Ubuntu in the folder structure of the link below.

When building a virtual environment other than Ubuntu, refer to the URL below.

About the environment

Host environment

This environment is required on the host side to build a virtual environment.

If you have not installed VirtualBox/Vagrant, please refer to the page below to install it.

Build environment

The script to be executed this time will install the following OS and software in the virtual environment.

  • Ubuntu 20.04: I am using Box (a virtual terminal template for Vagrant) published by Chef Software.
  • Docker
  • Docker-compose
  • Jenkins: Japanese CI/CD tool for OSS.Built on Docke.
  • Growi: A Japanese Wiki that can be written in OSS Markdown.Built on Docke.

Download build script

Download the script file for building the environment from here and unzip it to an appropriate folder.

Please do not change the folder structure of the downloaded script file, because some of them are referenced with a relative path when executing the script.

If you cannot execute the downloaded script file by double-clicking it according to the procedure, check the page below.

Virtual environment construction procedure

Execute /vm-configure/host-osx/ubuntu-20.04/vm-create.command included in the downloaded building script by terminal or double-click to download and install required software such as Ubuntu or Docker. A virtual environment is built.

When the script is executed, Launchd is modified to execute the script for starting and stopping the guest OS (Ubuntu) when the host OS (Mac OS) starts and stops.Without this script, if you accidentally stop your Mac before stopping it, your virtual machine may be killed and corrupted.

SSH connection to Ubuntu

You can connect to the built virtual machine of Ubuntu 20.04 by SSH.

To connect, open the /vm-configure/host-osx/ubuntu-20.04/ folder in your terminal and run the following command:

vagrant ssh

The admin user and password for Ubuntu 20.04 is vagrant/vagrant.

After SSH connection, you can operate with commands as you would with normal Ubuntu.

Growi

If you open http://192.168.33.101 in the browser of the host OS, you can open the initial setting screen of Growi.

Jenkins

You can open the Jenkins initial setting screen by opening http://192.168.33.101 in the browser of the host OS.

Virtual environment startup procedure

Run /vm-configure/host-osx/ubuntu-20.04-start.command included in the downloaded build script in aterminal or double-click to start the Ubuntu 20.04 virtual machine.

The virtual machine needs to be started/stopped by a script to read the configuration file.

Procedure for stopping the virtual environment

Run the /vm-configure/host-osx/ubuntu-20.04-stop.command included in the downloaded build script in terminal or double click to stop the Ubuntu 20.04 virtual machine.

The virtual machine needs to be started/stopped by a script to read the configuration file.

Procedure for destroying virtual environment

When you execute /vm-configure/host-osx/ubuntu-20.04/vm-destroy.command included in the downloaded building script by terminal or double-click, the message below is displayed, so enter “y”. Then press “Enter” key to delete the Ubuntu 20.04 virtual machine.

vm1: Are you sure you want to destroy the'vm1' VM[y/N]?

The script added to Launchd during virtual environment construction is also deleted.

GitHub

The script I used is available on GitHub.

GitHub - Collbow/vm-configure: Virtual machine configurate
Virtualmachineconfigurate.ContributetoCollbow/vm-configuredevelopmentbycreatinganaccountonGitHub.

Comment

スポンサーリンク