Ubuntu19.04にDockerをインストール

Ubuntu19.04にDockerをインストール

dockerは非常に便利なので、Ubuntu19.04にdockerをインストールした際の手順を記述してます。

Ubuntuバージョン

Ubuntu19.04

インストール準備

公式手順を参考にインストールを行ってます。必要なものを事前にインストールしておく

## 面倒なのでrootに
sudo su -

## インストールコマンド
apt install -y \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common

Dockerの公式GPG keyを追加 ( GPG は暗号化を行うツール )

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

OK

フィンガープリントの確認

## 確認
apt-key fingerprint 0EBFCD88

<出力結果>

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [  不明  ] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

公式サイトと一致しているので問題なし

repositoryを追加

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

## もう一度アップデート
apt update

Dockerのインストール

インストール

apt install -y docker-ce

hello-worldしてみる

docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

指定ユーザーもsudoなしで実行可能に

## testuserを追加
gpasswd -a testuser docker

## 確認
cat /etc/group|grep docker

docker:x:998:testuser

## testuserで実行
docker ps

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:

怒られたので

## permissionの変更
sudo chmod 666 /var/run/docker.sock

## 問題なし
docker ps