LoginSignup
9
16

More than 3 years have passed since last update.

Windows10上のVirtualBoxで稼働するUbuntuにDockerをインストール

Last updated at Posted at 2020-05-26

概要

Ubuntuで、pythonを実行できる環境を整備したいが、pythonは頻繁にバージョンアップするし、プログラムの目的ごとにpipで追加したいパッケージのバージョンが異なったりする。
venv(または、pyenv等)で切り替えることも検討したが、もういっそコンテナの方が便利かも・・・
ということで、Windows10上のVertualBoxで稼働するUbuntuにDockerをインストールする手順・・・

基本的には、以下に記載の手順通り。
「Install Docker Engine on Ubuntu」
https://docs.docker.com/engine/install/ubuntu/

Windows10のVirtualBoxインストール手順はこちら
VirtualBox

VirtualBoxにUbuntuをインストールする手順はこちら
Ubuntu

前準備

既存Dockerの確認

Ubuntuにログイン。
[アクティビティ]-[アプリケーションを表示する]を選択。
[端末]を起動し、以下のコマンドを実行し、Dockerがinstallされていないことを確認する。

apt list --installed | grep docker

001.png

もしインストールされていたら、先に削除しておくことをお勧め。

sudo apt remove docker docker-engine docker.io containerd runc

Dockerフォルダの確認

以下のコマンドを実行し、旧バージョンの残骸がないことを確認する。

ls /var/lib

002.png
dockerフォルダがないことを確認

もし存在していたら、削除しておく。

sudo rm -rf /var/lib/docker

リポジトリの設定

必要なコマンドの追加

以下のコマンドを実行し、リポジトリ追加のために必要なコマンドがインストールされているか確認する。

apt list --installed | grep apt-transport-https
apt list --installed | grep ca-certificates
apt list --installed | grep curl
apt list --installed | grep gnupg-agent
apt list --installed | grep software-properties-common

003.png
上記の結果を確認し、インストールされていないものをインストール。
(例では、ca-certificates、software-properties-commonはインストールされているのでインストール不要。)

sudo apt install apt-transport-https
sudo apt install ca-certificates
sudo apt install curl
sudo apt install gnupg-agent
sudo apt install software-properties-common

004.png
005.png
006.png

apt-keyの設定

以下のコマンドを実行。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

確認

sudo apt-key fingerprint 0EBFCD88

007.png

リポジトリ追加

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

008.png

インストール

以下のコマンドを実行。

sudo apt install docker-ce

101.png
途中確認ダイアログが表示されたら、yを入力し、[Enter]キーを押下。
102.png
インストール終了。

動作確認

以下のコマンドを実行。

sudo docker version

103.png
バージョン情報が正しく表示されていることを確認。

以下のコマンドを実行。

sudo docker run hello-world

104.png
正常にDockerが動作することを確認。

Docker実行権限の追加

一般ユーザエラー

デフォルトの状態では、rootユーザしかdockerを使用できない。

201.png

権限追加

一般ユーザでdockerを使用するためには、以下の権限追加が必要。

sudo usermod -a -G docker (権限追加するユーザ)

反映させるためには、再起動。
(systmctl restart dockerを実行し、当該ユーザのターミナルを再接続してもOK。)

sudo reboot

202.png

動作確認

以下のコマンドを実行。

docker run hello-world

203.png
一般ユーザでdockerを使用できるようになった。

参考

9
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
16