1. Mac に VirtualBox をインストール
Homebrew のサイトでスクリプトを確認し、terminal で実行する
2020年10月25日時点では下記のスクリプト
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Homebrew を利用して Mac に VirtualBox をインストールする
brew update && brew upgrade && brew upgrade --cask
brew cask install virtualbox
2. VirtualBox に Ubuntu をインストール
Ubuntu のイメージをダウンロードする
- Ubuntu.com - Get Ubuntu
virtualbox に Ubuntu をインストールする
- LIFESTYLE LAB - やっとできた!MacのVirtualBox上にUbuntuをインストールする方法
Ubuntu に Guest Additions をインストールする
- Qiita - MacでUbuntuを快適に使う
3. Ubuntu への SSH 接続を設定
- with FPGA - Mac 上のVirtual Box のUbuntu にSSH でアクセスしX転送する
Ubuntu にホストオンリーアダプタを設定する
- VirtualBox 上の Ubuntu の電源を落としておく
- VirtualBox > File > Host Network Manager... を選択する
- Create ボタンを押して vboxnet0 を作成する
- DHCP Server は Enable にチェックする
- Host Network Manager のウィンドウを Close する
- VirtualBox の Settings ボタンを押す
- Network タブを選択する
- Adapter 2 を選択する(選択できなければ VirtualBox をいちど再起動する)
- Enable Network Adapter にチェックを入れる
- Attached to: で Host-only Adapter を選択する
- OK ボタンを押す
Ubuntu に openssh-server をインストールする
VirtualBox 上の Ubuntu を起動し、terminal を開いて下記コードを実行する
sudo apt update && sudo apt upgrade
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl restart ssh
ip address
3: enp0s8
に 割り振られた inet
の IP アドレスを確認する。
Mac からの SSH 接続を確立する
Mac の terminal で下記のような形式のコードを実行し、SSH 接続する
ただし、<user>
は Ubuntu 上のユーザー名、<ip>
は上記で確認した IP アドレス
例:ssh foo@192.0.2.0
ssh <user>@<ip>
以降は Ubuntu に SSH 接続した Mac の terminal から全て操作する
4. Ubuntu に Docker をインストール
- docker docs - Install Docker Engine on Ubuntu
Uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
SET UP THE REPOSITORY
Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88
Use the following command to set up the stable repository.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
INSTALL DOCKER ENGINE
Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-world
sudo なしで docker を扱う
- docker docs - Manage Docker as a non-root user
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world