入社3年目 インフラ女子の備忘録

入社3年目のインフラ女子があれこれ悩みながら&つまずきながら、サーバ構築やプログラミングの手順を備忘録的に残していくブログ

【初心者向け】dockerでコンテナを作ってみたい(Dockerインストール編)

こんにちは、ぴよまるです。
今私の会社ではVMwareで仮想サーバを乱立させる運用方法をしています。
自分の環境(mac)の上にESXiサーバを構築して、その上に仮想サーバを...ということもやれなくはないのですが、私のmacちゃんが耐えられるのか...?という心配の方が大きく、何か違う方法でやれないものか。と思っていた所でした。
世間のアプリケーション開発を行う企業ではコンテナ化がどんどん進み、仮想サーバの構築なんて遅くてやってらんない〜時代はコンテナっしょ?なんて話も聞くので、いい機会だしdockerを使ってコンテナの上でシステムを構築してみることにしました。

1. Dockerをインストールしよう!

コマンドプロンプトから以下のコマンドを使用して、インストールを行います。無事インストールが完了すると、/ApplicationにDockerのクジラアイコンができていると思います。

brew cask install docker

2. Docker アカウントを作成しよう!

hub.docker.com
Docker Hubからアカウントを作成します。
入力項目はDocker ID、E-mail、パスワードです。
作成を進めていくと、課金額設定の項目が出てきますが、今回は私はローカルでの検証目的なので、無料のものを選択しました。
ここは用途に合わせて選択してください。

f:id:GRWM_ITInfra:20200813130833p:plain

3 Docker Desktopアプリを立ち上げてサインインしよう!

/Applicationに入っていたクジラのアイコンを開くと、サインインの画面が出てきます。
ここに先ほど作成したアカウント情報を使ってログインします。
f:id:GRWM_ITInfra:20200813131621p:plain

4 Dockerが動くか確認しよう!

f:id:GRWM_ITInfra:20200813132033p:plain
デスクトップの右上にDockerのアイコンがあることを確認します。
そしたらコマンドプロンプトに戻って、念のためDockerが動いていることを、Dockerのバージョン確認のコマンドを使って確認します。

$docker --version:version
Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:49:27 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

19.03.12が入っているようですね。

ちなみにdockerと打つと、使用可能なコマンドやオプションを一覧で出してくれます。

$docker
Usage:	docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Management Commands:
  builder     Manage builds
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

5. Dockerインストール完了

ここまででDockerのインストールが無事に完了です!次からはコンテナを作成していきたいと思います!