# Dockerを利用してさっと検証環境構築

## Dockerを利用してさっと検証環境構築

### OS

```
# Amazon Linux AMI
$ docker run -it amazonlinux:2018.03.0.20180827 /bin/bash

# Amazon Linux2
$ docker run -it amazonlinux:2.0.20180827 /bin/bash

# CentOS6
$ docker run -it centos:centos6 /bin/bash

# CentOS7
$ docker run -it centos:centos7 /bin/bash

# Ubuntu
$ docker run -it ubuntu:18.04 /bin/bash

# Debian
$ docker run -it debian:latest /bin/bash

# openSUSE
$ docker run -it opensuse:leap /bin/bash
```

### OSS

#### MySQL

```
# 5.6.41
$ docker run --name mysql5.6.41 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.6.41
$ docker exec -it mysql5.6.41 mysql -u root -p

# 5.7.23
$ docker run --name mysql5.7.23 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7.23
$ docker exec -it mysql5.7.23 mysql -u root -p
```

IP アドレスでローカルの MySQL クライアントからアクセスする場合は、`ip addr show` コマンドの実行結果で inet が IPv4 の utun デバイスの IP アドレスを確認(ここでは、10.85.11.170)

```
$ mysql -h 10.85.11.170 -u root -p
```

#### PostgreSQL

```
$ docker run --name postgres9.6 -p 5432:5432 -e POSTGRES_USER=hayashier -e POSTGRES_PASSWORD=password -d postgres:9.6
$ docker exec -it postgres9.6 psql -U hayashier
```

#### Nginx

```
$ docker run -p 80:80 --name webserver nginx
```

動作確認

```
$ curl localhost
```

#### Apache

```
$ docker run -p 80:80 --name webserver httpd
```

動作確認

```
$ curl localhost
```

#### Squid

```
$ docker run -p 3128:3128 --name squid poklet/squid
```

動作確認

```
$ curl --proxy http://localhost:3128 -vo /dev/null https://hayashier.com

$ docker exec -it squid /bin/bash
```

#### OpenLDAP

```
$ docker run --name ldap-service --hostname ldap-service --detach osixia/openldap
$ docker run --name phpldapadmin-service -p 6443:443 --hostname phpldapadmin-service --link ldap-service:ldap-host --env PHPLDAPADMIN_LDAP_HOSTS=ldap-host --detach osixia/phpldapadmin
```

動作確認

ブラウザで <https://localhost:6443/> へアクセス。\
Login DN: cn=admin,dc=example,dc=org , Password: admin

```
$ docker exec -it ldap-service /bin/bash
# ldapsearch -x -H ldap://localhost -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin
```

## Dockerイメージ掃除

プロセスが終了していることを確認した上で、イメージの削除を行う。

```
# Docker プロセス確認
$ docker ps

# Docker プロセス終了
$ docker kill <CONTAINER ID 1> <CONTAINER ID 2> ...
```

一括で消せない場合は、docker ps/images で対象の ID を確認しながら、docker rm/rmi

```
# コンテナ一括削除
$ docker ps -aq | xargs docker rm

# イメージ一括削除
$ docker images -aq | xargs docker rmi
```

## 参考

* library/amazonlinux - Docker Hub\
  <https://hub.docker.com/\\_/amazonlinux/>
* centos - Docker Hub\
  <https://hub.docker.com/\\_/centos/>
* ubuntu - Docker Hub\
  <https://hub.docker.com/\\_/ubuntu/>
* debian - Docker Hub\
  <https://hub.docker.com/\\_/debian/>
* opensuse - Docker Hub\
  <https://hub.docker.com/r/opensuse/leap/>
* mysql/mysql-server\
  <https://hub.docker.com/r/mysql/mysql-server/>
* postgres\
  <https://hub.docker.com/\\_/postgres/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hayashier.gitbook.io/article/containers/setup-test-environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
