aws ec2 docker 部署


又折騰了好久才部署上去,不偷懶,記下來。

 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM