ecs-cli卡住创建容器

时间:2017-09-22 14:41:03

标签: docker-compose aws-cli amazon-ecs

我正在尝试使用ecs-cli命令行在AWS上获得一个有效的Docker环境。

我有一个使用Dockerfiles,docker-compose.yml,.env文件和entrypoint.sh脚本的本地Docker环境。容器是一个运行PHP和一堆扩展的apache webserver,以及一个MySQL db。

骨架文件结构如下:

./db <-- mounted by db container for persistence
./docker
./docker/database
./docker/database/Dockerfile
./docker/database/dump.sql
./docker/webserver
./docker/webserver/apache-config.conf
./docker/webserver/Dockerfile
./docker/webserver/entrypoint.sh
./docker-compose.yml
./web <!-- mounted by web server, contains all public web code

这是2个Docker文件:

./搬运工/数据库/ Dockerfile

FROM mysql:5.6
ADD dump.sql /docker-entrypoint-initdb.d

./搬运工/网络服务器/ Dockerfile

FROM php:5.6-apache
RUN apt-get update 
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y zlib1g-dev nodejs gdal-bin
RUN npm install -g topojson
RUN docker-php-ext-install mysql mysqli pdo pdo_mysql zip
RUN pecl install dbase
RUN docker-php-ext-enable dbase
COPY apache-config.conf /etc/apache2/sites-enabled/000-default.conf
RUN a2enmod rewrite headers
RUN service apache2 restart
COPY entrypoint.sh /entrypoint.sh
RUN chmod 0755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh", "apache2-foreground"]

entrypoint.sh在web目录中创建了一些目录,供apache写入:

./搬运工/网络服务器/ entrypoint.sh     #!/ bin / sh的

mkdir /var/www/html/maps
chown www-data /var/www/html/maps
chgrp www-data /var/www/html/maps
exec "$@"

这里是docker-compose.yml

version: '2'

services:
  webserver:
    image: ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-webserver
    ports:
      - "8080:80"
    volumes:
      - ./web:${APACHE_DOC_ROOT}
    links:
      - db
    environment:
      - HTTP_ROOT=http://${DOCKER_HOST_IP}:${DOCKER_HOST_PORT}/
      - PHP_TMP_DIR=${PHP_TMP_DIR}
      - APACHE_LOG_DIR=${APACHE_LOG_DIR}
      - APACHE_DOC_ROOT=${APACHE_DOC_ROOT}/
      - SERVER_ADMIN_EMAIL=${SERVER_ADMIN_EMAIL}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
    env_file: .env

  db:
    user: "1000:50"
    image: ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-database
    ports:
      - "4406:3306"
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
    env_file: .env

要构建那里引用的图像:

  • 使用管理员权限创建AWS IAM用户,并在配置文件名称下设置〜/ .aws /凭证中的密钥,然后使用设置本地ENV 导出AWS_PROFILE = my-project-profile

  • 然后在本地构建图像,如下所示:

    docker / webserver $ docker build -t ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-webserver。

    docker / database $ docker build -t ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-database。

  • 让docker登录到ECR(运行docker login命令echo&#39; d到std-out):

    $ aws ecr get-login --no-include-email

  • 创建了回购:

    $ aws ecr create-repository --repository-name project / project-webserver

    $ aws ecr create-repository --repository-name project / project-database

  • 推送图片:

    $ docker push ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-webserver

    $ docker push ACCOUNT_NUMBER.dkr.ecr.eu-west-1.amazonaws.com/project/project-database

  • 检查过他们在那里:

    $ aws ecr describe-images --repository-name project / project-webserver

    $ aws ecr describe-images --repository-name project / project-database

一切都很好。

  • 在同一地区创建了一个EC2密钥对

    $ ecs-cli configure --region eu-west-1 --cluster project $ cat~ / .ecs / config

  • 试图在ECS上运行它们:

    $ ecs-cli up --keypair project --capability-iam --size 1 --instance-type t2.micro --force

但是,如果我在生成的EC2实例的安全组中打开端口22并且在SSH中我可以看到代理容器正在运行,但没有其他人运行:

[ec2-user@ip-10-0-0-122 ~]$ docker ps -a
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS               NAMES
d011f1402c26        amazon/amazon-ecs-agent:latest   "/agent"            8 minutes ago       Up 8 minutes                            ecs-agent

我在代理商的日志中看不到任何不良内容

[ec2-user @ ip-10-0-1-102~] $ docker logs ecs-agent

2017-09-22T13:32:55Z [INFO] Loading configuration
2017-09-22T13:32:55Z [INFO] Loading state! module="statemanager"
2017-09-22T13:32:55Z [INFO] Event stream ContainerChange start listening...
2017-09-22T13:32:55Z [INFO] Registering Instance with ECS
2017-09-22T13:32:55Z [INFO] Registered! module="api client"
2017-09-22T13:32:55Z [INFO] Registration completed successfully. I am running as 'arn:aws:ecs:eu-west-1:248221388880:container-instance/ba24ead4-21a5-4bc7-ba9f-4d3ba0f29c6b' in cluster 'gastrak'
2017-09-22T13:32:55Z [INFO] Saving state! module="statemanager"
2017-09-22T13:32:55Z [INFO] Beginning Polling for updates
2017-09-22T13:32:55Z [INFO] Event stream DeregisterContainerInstance start listening...
2017-09-22T13:32:55Z [INFO] Initializing stats engine
2017-09-22T13:32:55Z [INFO] NO_PROXY set:169.254.169.254,169.254.170.2,/var/run/docker.sock
2017-09-22T13:33:05Z [INFO] Saving state! module="statemanager"
2017-09-22T13:44:50Z [INFO] Connection closed for a valid reason: websocket: close 1000 (normal): ConnectionExpired: Reconnect to continue

我想我需要弄清楚为什么这些容器不能进行初始化,但我在哪里看,更好的是,我需要做些什么才能让它工作?

1 个答案:

答案 0 :(得分:0)

如果其他人在这里漂流,那么缺少的咒语就是 $ ecs-cli compose create 它从您的撰写文件构建ECS任务定义(假设它是兼容的......)

$ecs-cli compose run 这将在远程EC2机器上构建和运行容器。

SSH到远程机器并执行&#34; docker ps -a&#34;应该显示容器正在运行。或者&#34; docker logs [container_name]&#34;看看出了什么问题...