【问题标题】:AWS Launch sample webite in docker on ec2 instanceAWS 在 ec2 实例上的 docker 中启动示例网站
【发布时间】:2020-02-12 16:26:17
【问题描述】:

我需要一些帮助,在 docker 中使用 ansible 在 ec2 实例中部署一个简单的网站。 目前,我有一个提供 ec2 实例的剧本,但我希望能够安装 docker 和 apache 服务器并部署一个简单的网站。例如,只是一个简单的网页打招呼,所以我知道它正在工作。我不知道该怎么做

- name: deploy Ec2 Instances
  hosts: localhost
  connection: local
  gather_facts: true

  tasks:
  - name: Launch ec2 instance
    ec2:
      instance_type: t2.micro
      key_name: mykeypair
      image: ami-00eb20669e0990cb4
      region: us-east-1
      group: default
      count: 1
      vpc_subnet_id: subnet-ed43648a
      wait: yes

【问题讨论】:

  • 你说的是docker但是docker镜像在哪里?

标签: docker amazon-ec2 ansible


【解决方案1】:

以下非常简单的方法应该适合您的需求:

编辑(对于这个 apache 示例,不需要自定义 Dockerfile)!

您可以在 docker-compose.yml 文件中引用 apache(该文件必须位于相对于您的 playbook 文件的文件或模板目录中):

version: '3.7'
services:
  apache:
    image: httpd:2.4-alpine
    ports:
      - "80:80"

将这些任务添加到您的游戏中:

# you probably have to create your Docker Directories first and check for existence of your files on the host

...

- name: "transfer dockerfiles for service"
  template:
    src: docker-compose.yml
    dest: "/home/ec2-user/deploy/apache/docker-compose.yml"
    mode: 0755
    trim_blocks: no

- name: "(re)start service"
  shell: |
    cd /home/ec2-user/deploy/apache
    docker-compose up --build -d

完成此 playbook 运行后,您可以简单地在主机本身上 curl localhost/index.html。

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2015-08-24
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多