aws ec2 docker 部署

本文详细介绍了如何在Amazon EC2上部署Web应用,包括配置安全组规则、启动数据库和Web容器、创建容器间连接及数据库操作等内容。

又折腾了好久才部署上去,不偷懒,记下来。

 

1. 在EC2的安全组里设置入站、出站的端口、ip、协议等,确保实例应用了新添加的安全组规则

 

2. 启动数据库container, 命名为db

sudo docker run --name db mongo

 

3. 根据Dockerfile,生成网站的image

sudo docker build -t web_image .

-t 设置这个image的名字

 

4. 启动web container

sudo docker run -d --name web -p 80:8000 --link db:mongo web_image

-d 表示后台运行,换成-it则进入interactive模式

-p 端口映射

--link 连接web和db这两个container,注意这里是db:mongo,所以connectionUrl需要是mongodb://mongo:27017/dbName

 

==================== UPDATES ==========================

When it comes to mysql image

sudo docker pull mysql

Must specify an initial root password. Since containers are isolated, if you want to have access to files (e.g. sql scripts) outside the container, you need to mount them.

sudo docker run --name my_sql_container -e MYSQL_ROOT_PASSWORD=my_initial_password --mount type=bind,source="$(pwd)",target=/data -d mysql

Then you can access files under the current directory through /data in this container.

And again, in the code where db connection is created, use 'mysql' as the host name, NOT 'localhost'.

 

 

export database into sql file

mysqldump -u root -p db_name > file_name.sql

 

run sql script to populate database (in mysql), make sure you have created the database and used it.

source file_name.sql

 

转载于:https://www.cnblogs.com/coiorz/p/8426184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值