Help us understand the problem. What is going on with this article?

Ubuntu 18.04にDockerをインストールする(+docker-composeも)

More than 1 year has passed since last update.

アジェンダ

repositoryをアップデートする

  • apt パッケージのアップデート
sudo apt update
  • HTTPS経由でrepositoryをやりとり出来るようにするためのパッケージをインストール
sudo apt install -y \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common
  • Dockerの公式GPG keyを追加する
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • repository( stable ) を追加する
sudo add-apt-repository \
     "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
     $(lsb_release -cs) \
     stable"
  • 再度 apt パッケージのアップデート
sudo apt update

docker をインストールする

  • インストール・起動
sudo apt install -y docker-ce
  • 起動確認
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-07-09 17:51:00 JST; 58s ago
     Docs: https://docs.docker.com
 Main PID: 3920 (dockerd)
    Tasks: 16
   CGroup: /system.slice/docker.service
           tq3920 /usr/bin/dockerd -H fd://
           mq3935 docker-containerd --config /var/run/docker/containerd/containerd.toml
  • プロセスの確認(sudo有)
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

指定の一般ユーザでも sudo 無しでdockerを使えるようにする

  • 初期設定では出来ない
$ whoami
iganari
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.37/containers/json: dial unix /var/run/docker.sock: connect: permission denied
  • 一般ユーザ( iganari )をDockerグループに追加する
### 確認
$ cat /etc/group | grep docker
docker:x:999:


### 追加
sudo gpasswd -a iganari docker


### 確認
$ cat /etc/group | grep docker
docker:x:999:iganari
  • dockerが使用するソケットを一般ユーザでも読み込み出来るようにする
sudo chmod 666 /var/run/docker.sock
  • プロセスの確認(sudo無)
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

docker-composeをインストール

export compose='1.21.1'
  • /usr/local/bin/ 配下にダウンロード
sudo curl -L https://github.com/docker/compose/releases/download/${compose}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • 実行権限の付与
sudo chmod 0755 /usr/local/bin/docker-compose
  • 確認(sodo無)
$ docker-compose -v
docker-compose version 1.6.2, build 4d72027

以上でやりたいことが出来ました 😉

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away