Windows10 Pro + Hyper-V + Docker for Windows + GitHab CE
はじめに
GitLabを使うらしいので、自由使える環境を手元に作る。すでWindows7 + VirtualBox + Centos7 + GitHab CEは作れた。しかしWindows10 ProはVirtualBoxではなくHyper-Vをデフォにしている(両者は共存できない)。そうなるとWindows10 Pro + Hyper-V + Ubuntu + GitHab CEなんだけど面白くない。そもそもGitHab CEを使いたいのであって、CentsOS7とかUbuntuのことはあまり考えたくない。ということもあり、今回はDockerを使い、Windows10 Pro + Hyper-V + Docker for Windows + GitHab CEな環境を作ってみた。以下その手順。
Docker for Windowのインストール
①Install Docker Desktop on Windowsにアクセスして、[Download from Docker Hub]をクリックする。
②Docker IDを持っていない場合、[Sign up]をクックする。
③認証情報を入力する。
- Docker ID、パスワード、Emailアドレスを入力する。
- Emailはこの後、最終確認で使われるので、自分が受け取れるアドレスを使う。
- 最後に[Continue]をクリックする。
④プロフィール情報を入力して、[Continue]をクリックする。
⑤入力完了。
⑥③で入力したEmailアドレスに確認メールが届いたら[Confirm Your Email With Docker]をクリックする。
⑦ダウンロード画面が表示されたら、[Get started with Docker Desktop]をクリックする。
⑧[Download Docker Desktop for Windows]をクリックする。
⑨ダウンロードしたDocker Desktop Installer.exeを実行する。 ⑩ [Close and log out]をクリックする。 ⇒いったんログアウトするので未保存のファイルがあるときは注意。
⑬ログインしなおす。
⑭しばらくすると右下にウィンドウが表示されるので、Docker ID/パスワードを入力して[Log In]を押下する。
⑮⑭に書かれてたようにお好きなターミナルソフトを起動してDockerが入ったか確認する。 ここではコマンドプロンプトを起動して docker コマンドを実行 ⇒ヘルプが表示される
C:\>docker Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "C:\\Users\\uranus\\.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "C:\\Users\\uranus\\.docker\\ca.pem") --tlscert string Path to TLS certificate file (default "C:\\Users\\uranus\\.docker\\cert.pem") --tlskey string Path to TLS key file (default "C:\\Users\\uranus\\.docker\\key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit 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 Run 'docker COMMAND --help' for more information on a command. C:\>
次はdocker --version でversion表示。
C:\>docker --version Docker version 19.03.5, build 633a0ea C:\>
大丈夫そう。
GitLabのインストール
基本、GitLabのイメージを取得して実行するだけ。入手元はGitLab Docker。ただし以下のような注意書きがあるので要注意 by Google翻訳。
注意: Docker for Windowsでの実行は公式にはサポートしていません。ボリュームのアクセス許可には既知の問題があり、その他の未知の問題もある可能性があります。Docker for Windowsで実行しようとしている場合、コミュニティリソース(IRC、フォーラムなど)へのリンクのヘルプページを参照して、他のユーザーからの助けを求めてください。
上記サイトに記載されているインストールコマンドは以下の通り。
docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
ただしDocker for Windowsをコマンドプロンプトから実行しているので、入力は1行にする。
docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
実行するとこんな感じになる。
C:\>docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest Unable to find image 'gitlab/gitlab-ce:latest' locally latest: Pulling from gitlab/gitlab-ce e80174c8b43b: Pull complete d1072db285cc: Pull complete 858453671e67: Pull complete 3d07b1124f98: Pull complete be2fffc6bf6b: Pull complete 40d45553fd44: Pull complete 38935478f630: Pull complete 0f8cc1994627: Pull complete 39dde03ad145: Pull complete 3d0bbed7e185: Pull complete Digest: sha256:6d4e2b1b884ae3214621249c6c8b05539303d168b1423cd26c377f9ded1c3f01 Status: Downloaded newer image for gitlab/gitlab-ce:latest 8d384680de8b51a60e8448c1b9d0e0879153e02440be6abe03daebbcbaf833f6 C:\>
ただし、この時点では、まだバックグラウンドでGitLabの構成処理が実行されている。
C:\>docker logs -f gitlab
を実行すると、gitlabが設定されている状況が見える。そして
==> /var/log/gitlab/gitlab-rails/production.log <==
のような表示が始まったら、たぶん設定完了。
ブラウザから http://localhost/で以下のような画面が出たら終わり。
なおdocker logsは[CTRL]+[C]で抜けられる。 あとGitLabのコンテナをWindows上で構築したいも見ておくと幸せに少し近づける気がする。