0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS 7 に docker-ce、docker-compose をインストールして一般ユーザで動かす

Last updated at Posted at 2019-08-14

概要

OpenStack上の仮想マシンで稼働している社内システムをDockerへ移行したので、その際の導入手順をメモ。
環境は以下の通り。

  • CentOS 7
  • Docker CE 18.08.8
  • Docker Compose 1.24.0

Docker CE インストール

既にDockerがインストール済みかどうか確認。インストール済みならyum removeでアンインストール。

# yum list installed | grep docker

必要パッケージのインストール。

# yum install yum-utils \
  device-mapper-persistent-data \
  lvm2

Docker CEのリポジトリを追加。

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Docker CEのインストール。

# yum install docker-ce

Dockerサービスを起動。

# systemctl start docker

Dockerサービスを有効化。

# systemctl enable docker

Docker Compose インストール

最新版はGitHubのページで確認。

# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose

Dockerを一般ユーザで動かせるよう設定

adminユーザを作成して、そこでDockerを使えるよう設定。
※ この設定は商用環境では非推奨。あくまで社内や開発環境向け。

# useradd admin
# passwd admin
# usermod -aG docker admin

動作確認

adminユーザで確認してみる。

# su - admin
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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/


$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES
e118c3d45615        hello-world         "/hello"            About a minute ago   Exited (0) About a minute ago                       peaceful_swartz

$ docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
hello-world                                     latest              fce289e99eb9        7 months ago        1.84kB

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?