---
# System prepended metadata

title: Cloud9とdocker-composeに関する技術調査
tags: [technology]

---

---
tags: technology
---
# Cloud9とdocker-composeに関する技術調査


## AWS Cloud9

### セキュリティグループ
![](https://i.imgur.com/laBGXcr.png)

### EC2
t3.large (2 GiB RAM + 2 vCPU)
ボリューム 20GB

![](https://i.imgur.com/fQSfzeM.png)

### docker バージョン
```shell=
$ docker -v
Docker version 20.10.17, build 100c701
$ docker-compose -v
docker-compose version 1.27.0, build 980ec85b
```

## docker-compose.yml
```yaml=
version: '3'
services:
  code: &code
    build: ./
    env_file:
      - ./.env
    volumes:
      - ./:/app
    ports:
      - 9040:9040
      - 9041:9041
    working_dir: /app
    command: /bin/sh -c "while sleep 1000; do :; done"
    depends_on:
      - dynamodb
      - elasticsearch
      - localstack
    networks:
      local:
    logging: &logging
      driver: json-file
      options:
        max-file: '1'
        max-size: 3m
  localstack:
    image: localstack/localstack:0.14
    environment:
      - SERVICES=${SERVICES- }
      - DEBUG=${DEBUG- }
      - DATA_DIR=${DATA_DIR-/app/localstack}
      - PORT_WEB_UI=${PORT_WEB_UI- }
      - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=${TMPDIR}
      - DISABLE_CORS_CHECKS=${DISABLE_CORS_CHECKS-true}
    volumes:
      - '${TMPDIR:-/tmp/localstack}:/tmp/localstack'
      - '/var/run/docker.sock:/var/run/docker.sock'
      - './localstack:/app/localstack'
    ports:
      - 9042:4566
    networks:
      local:
    logging:
      <<: *logging
  dynamodb:
    image: amazon/dynamodb-local:latest
    command: -jar DynamoDBLocal.jar -sharedDb -dbPath /data
    volumes:
      - ./dynamodb:/data
    networks:
      local:
    logging:
      <<: *logging
  dynamodb-admin:
    image: aaronshaf/dynamodb-admin
    environment:
      - DYNAMO_ENDPOINT=http://dynamodb:8000
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID-local}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY-local}
      - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION-local}
    ports:
      - 9043:8001
    networks:
      local:
    restart: always
    logging:
      <<: *logging
  elasticsearch:
    build: ./elasticsearch
    environment:
      - 'discovery.type=single-node'
      - 'indices.fielddata.cache.size=30%'
      - ES_JAVA_OPTS=-Xms128m -Xmx128m
    volumes:
      - ./elasticsearch/data:/usr/share/elasticsearch/data:cached
    networks:
      - local
    logging:
      <<: *logging
  ngrok_9041:
    image: wernight/ngrok:latest
    environment:
      NGROK_PROTOCOL: http
      NGROK_PORT: code:9041
      NGROK_AUTH: ${NGROK_AUTH}
      NGROK_HOSTNAME: ${NGROK_9041_HOSTNAME}
      NGROK_REGION: jp
    networks:
      - local
    logging:
      <<: *logging
networks:
  local:
```
## docker起動
```shell=
$ docker-compose up -d
$ docker-compose ps
            Name                          Command                  State                                     Ports                              
------------------------------------------------------------------------------------------------------------------------------------------------
environment_code_1             docker-entrypoint.sh /bin/ ...   Up             0.0.0.0:9040->9040/tcp,:::9040->9040/tcp,                        
                                                                               0.0.0.0:9041->9041/tcp,:::9041->9041/tcp                         
environment_dynamodb-admin_1   docker-entrypoint.sh node  ...   Up             0.0.0.0:9043->8001/tcp,:::9043->8001/tcp                         
environment_dynamodb_1         java -jar DynamoDBLocal.ja ...   Up             8000/tcp                                                         
environment_elasticsearch_1    /tini -- /usr/local/bin/do ...   Exit 1                                                                          
environment_localstack_1       docker-entrypoint.sh             Up (healthy)   4510/tcp, 4511/tcp, 4512/tcp, 4513/tcp, 4514/tcp, 4515/tcp,      
                                                                               4516/tcp, 4517/tcp, 4518/tcp, 4519/tcp, 4520/tcp, 4521/tcp,      
                                                                               4522/tcp, 4523/tcp, 4524/tcp, 4525/tcp, 4526/tcp, 4527/tcp,      
                                                                               4528/tcp, 4529/tcp, 4530/tcp, 4531/tcp, 4532/tcp, 4533/tcp,      
                                                                               4534/tcp, 4535/tcp, 4536/tcp, 4537/tcp, 4538/tcp, 4539/tcp,      
                                                                               4540/tcp, 4541/tcp, 4542/tcp, 4543/tcp, 4544/tcp, 4545/tcp,      
                                                                               4546/tcp, 4547/tcp, 4548/tcp, 4549/tcp, 4550/tcp, 4551/tcp,      
                                                                               4552/tcp, 4553/tcp, 4554/tcp, 4555/tcp, 4556/tcp, 4557/tcp,      
                                                                               4558/tcp, 4559/tcp, 0.0.0.0:9042->4566/tcp,:::9042->4566/tcp,    
                                                                               5678/tcp                                                         
environment_ngrok_9041_1       /entrypoint.sh                   Exit 1                                                                          
```


## FRONTEND起動
```bash=
$ docker-compose exec -w /app/code/frontend code yarn dev
yarn run v1.22.19
$ vite

  VITE v3.0.9  ready in 539 ms

  ➜  Local:   http://localhost:9040/
  ➜  Network: use --host to expose

```

Cloud9からcurl→接続できない
```shell=
$ curl http://localhost:9040/
curl: (56) Recv failure: Connection reset by peer
```

『docker上のアプリにlocalhostでアクセスしたらERR_EMPTY_RESPONSEが出る - Qiita』
(https://qiita.com/amuyikam/items/01a8c16e3ddbcc734a46#17217098000--x--1270018000 )

『VM上でDockerを用いてnginxを起動しても接続がリセットされるエラー』
(https://teratail.com/questions/242468 )

dockerからcurl→接続できる
```shell=
$ docker-compose exec code bash
# curl http://localhost:9040/
<!--
=========================================================
* Vue Material Dashboard 2 - v3.0.0
=========================================================
（省略）
```

## FRONTENDのネットワーク
```shell=
$ docker network ls
NETWORK ID     NAME                DRIVER    SCOPE
984c86461bca   bridge              bridge    local
2e5e0a3a849f   environment_local   bridge    local
cec0678a3940   host                host      local
184ed7c02bc7   none                null      local

$ docker container ls --format='table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'
CONTAINER ID   NAMES                          STATUS                   PORTS
2a9b32c04878   environment_code_1             Up 8 minutes             0.0.0.0:9040-9041->9040-9041/tcp, :::9040-9041->9040-9041/tcp
4aacff57f20e   environment_localstack_1       Up 8 minutes (healthy)   4510-4559/tcp, 5678/tcp, 0.0.0.0:9042->4566/tcp, :::9042->4566/tcp
1513f479ba83   environment_dynamodb_1         Up 8 minutes             8000/tcp
f1f0243f5d02   environment_dynamodb-admin_1   Up 12 minutes            0.0.0.0:9043->8001/tcp, :::9043->8001/tcp
```

## portsに127.0.0.1を追加
docker-compose.yml
```yaml=
  code: &code
    ports:
      - "127.0.0.1:9040:9040"
      - "127.0.0.1:9041:9041"
```
```shell=
$ docker-compose up -d
$ curl http://localhost:9040/
curl: (56) Recv failure: Connection reset by peer
$ curl http://127.0.0.1:9040/
curl: (56) Recv failure: Connection reset by peer
```
## portsに127.0.0.1を追加
参考
https://github.com/localstack/localstack/blob/master/docker-compose.yml
https://poota.net/archives/833

docker-compose.yml
```yaml=
 localstack:
     ports:
      - "127.0.0.1:9042:4566"
      - "127.0.0.1:4566:4566"
```
```shell=
$ docker-compose up -d
$ curl http://localhost:9040/
curl: (56) Recv failure: Connection reset by peer
```

## グローバル IP にしてみる
docker-compose.yml
```yaml=
 localstack:
    ports:
      - "54.65.121.248:9042:4566"
      - "54.65.121.248:4566:4566"
```
```shell=
$ docker-compose up -d
Creating network "environment_local" with the default driver
Creating environment_localstack_1 ... 
Creating environment_localstack_1     ... error
Creating environment_ngrok_9041_1     ... 
Creating environment_dynamodb_1       ... 
Creating environment_elasticsearch_1  ... 
WARNING: Host is already in use by another container
Creating environment_dynamodb-admin_1 ... done
Creating environment_dynamodb_1       ... done
Creating environment_ngrok_9041_1     ... done
Creating environment_elasticsearch_1  ... done

ERROR: for localstack  Cannot start service localstack: driver failed programming external connectivity on endpoint environment_localstack_1 (92b09b9568e8e5f44cd10650406fbce428a139340398a55ea0f28f3b487860db): Error starting userland proxy: listen tcp4 54.65.121.248:4566: bind: cannot assign requested address
ERROR: Encountered errors while bringing up the project.
```

docker-compose.yml
```yaml=
  code: &code
    ports:
      - "54.65.121.248:9040:9040"
      - "54.65.121.248:9041:9041"
```
```shell=
$ docker-compose up -d
environment_dynamodb_1 is up-to-date
environment_dynamodb-admin_1 is up-to-date
Starting environment_ngrok_9041_1    ... done
Recreating environment_localstack_1  ... done
Starting environment_elasticsearch_1 ... done
Creating environment_code_1          ... 
Creating environment_code_1          ... error

ERROR: for environment_code_1  Cannot start service code: driver failed programming external connectivity on endpoint environment_code_1 (5d424215479c0044869e2b2fbb11a97b1703fa3670468b89fb92750839670d9d): Error starting userland proxy: listen tcp4 54.65.121.248:9041: bind: cannot assign requested address

ERROR: for code  Cannot start service code: driver failed programming external connectivity on endpoint environment_code_1 (5d424215479c0044869e2b2fbb11a97b1703fa3670468b89fb92750839670d9d): Error starting userland proxy: listen tcp4 54.65.121.248:9041: bind: cannot assign requested address
ERROR: Encountered errors while bringing up the project.
```

## プライベート IP にしてみる
docker-compose.yml
```yaml=
  code: &code
    ports:
      - "172.31.46.48:9040:9040"
      - "172.31.46.48:9041:9041"
```
```shell=
$ docker-compose up -d
$ curl http://localhost:9040/
curl: (7) Failed to connect to localhost port 9040 after 0 ms: Connection refused
$ curl 172.31.46.48:9040
curl: (7) Failed to connect to 172.31.46.48 port 9040 after 0 ms: Connection refused
```
docker-compose.yml
```yaml=
 localstack:
    ports:
      - "172.31.46.48:9042:4566"
```
```shell=
$ docker-compose up -d
$ curl http://localhost:9040/
curl: (56) Recv failure: Connection reset by peer
```



---
yum アップデート
```shell=
$ sudo yum update -y
```

## Docker インストール
```shell=
$ docker -v
Docker version 20.10.17, build 100c701
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose -v
docker-compose version 1.27.0, build 980ec85b
```

```shell=
$ docker-compose up -d
$ curl http://localhost:9040/
curl: (56) Recv failure: Connection reset by peer
```


### FRONTEND起動
```bash=
$ docker-compose exec -w /app/code/frontend code yarn dev
```








