Docker入门 (3) | 简单网站监控器

架构设计

在这里插入图片描述
2.实现
创建容器A并启动

sudo docker run -d -p 80:80 --name web nginx:latest

将80端口映射到本地端口,打开浏览器访问http://localhost/80

创建容器C并启动

sudo docker run --name mailer -d dockerinaction/ch2_mailer

创建容器B并启动,并且将b和web连接.

注意这里创建的是容器,并没有启动监控进程

docker run -i -t --link web:web --name web_test busybox /bin/sh

容器B是一个交互容器,运行后会进入shell模式,在shell模式访问80端口:

wget -O - http://web:80/

显示了nginx服务器的页面结果

Connecting to web:80 (172.17.0.4:80)

Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

扫描二维码关注公众号,回复: 10337740 查看本文章

由–tty(-t) 命令可以用键位ctrl+p+q来切换到终端

运行监控器

sudo docker run -it --name agent --link web:insideweb --link
mailer:insidemailer dockerinaction/ch2_agent

运行后会每秒一次显示web运行的状态

System up.

停止运行web

docker stop web

查看监控器日志

docker logs agent 

System up. System up. nc: timed out

查看邮件日志

CH2 Example Mailer has started. Sending email: To: admin@work
Message: The service is down!

发布了18 篇原创文章 · 获赞 4 · 访问量 345

猜你喜欢

转载自blog.csdn.net/qq_38929920/article/details/105194657