LoginSignup
8
11

More than 5 years have passed since last update.

Docker for Windows で CentOS 7 を起動するまで

Posted at

はじめに

Windows 10 にインストールしたDocker for Windowsで、CentOS 7 のイメージを検索、ダウンロード、起動、接続するまでの流れです。

CentOS 7 のイメージを検索

PS C:\> docker search --limit 5 centos
NAME                          DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                        The official build of CentOS.                   5034                [OK]
jdeathe/centos-ssh            CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86…   102                                     [OK]
openshift/base-centos7        A Centos7 derived base image for Source-To-I…   36
pivotaldata/centos-gpdb-dev   CentOS image for GPDB development. Tag names…   8
pivotaldata/centos            Base centos, freshened up a little with a Do…   2
オプション 説明
--limit 検索結果の表示数を指定した値に制限

名前空間が表示されていないcentosは公式リポジトリのイメージ。
以降では公式リポジトリのcentosを使用する。

CentOS 7 のイメージをダウンロード

PS C:\> docker image pull centos:centos7

公式リポジトリからcentosをダウンロード。
タグはcentos7を指定(省略可、もしくは任意のタグ)。

CentOS 7 のイメージを確認

PS C:\> docker image ls
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
centos                     centos7             1e1148e4cc2c        4 days ago          202MB

コンテナの作成と実行

PS C:\> docker container run --privileged -d --name TEST centos:centos7 /sbin/init
85ffcedeccc9ac1dcbd578fd1edfea30926b947861a54b87a20102230de51900
オプション 説明
--privileged このコンテナに対して拡張権限を与える
-d コンテナをバックグラウンドで実行し、コンテナIDを表示
-name コンテナに名前を割り当て

TESTという名前のコンテナをsystemctlが使用可能な状態で作成。

実行中のコンテナに接続

PS C:\> docker container exec -it TEST /bin/bash
[root@85ffcedeccc9 /]# 
オプション 説明
-i コンテナ側の標準入力との接続を継続する
-t 擬似端末を有効にする(ttyの割当)

実行中のTESTコンテナ内に新しいBashセッションを作成。
SSHで接続しているような感じで操作可能に。

8
11
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
8
11