docker - AWS 在 ec2 实例上的 docker 中启动示例网站
问题描述
我需要一些帮助在 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
解决方案
以下非常简化的方法应该适合您的需求:
编辑(对于这个 apache 示例,不需要自定义 Dockerfile)!
您可以在 docker-compose.yml 文件中引用 apache(该文件必须位于相对于您的 playbook 文件的 files 或 templates 目录中):
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。
推荐阅读
- sql - LIKE 运算符在 SQL (MS-Access) 中不起作用
- c++ - 为什么循环打印到 11 而不是 10?
- java - 无论如何调用排除模式的 Spring Boot 拦截器
- python - 将networkx图输入zss算法(树编辑距离)
- r - Sparklyr 用字符串填充
- android - 如何更改 phoenix/Elixir 中的数据验证?
- c# - IL“.custom instance void [attribute] = (...)”是什么意思?
- weblogic - 无法登录到 weblogic 控制台
- python - 使用 FileField 并在烧瓶中一起验证的问题
- c# - 字符串引用未设置为字符串的实例