Docker In Action 学习笔记 根据第二版有所更新
第一章
最简单的 hello_world/Dockerfile
FROM busybox:latest
CMD ["echo", "hello world"]
第二章
docker run --detach \
--name web \
nginx:latest
docker run -d \
--name mailer \
dockerinaction/ch2_mailer
docker run --interactive --tty \
--link web:web \
--name web_test \
busybox:1.29 /bin/sh
docker run -it \
--name agent \
--link web:insideweb \
--link mailer:insidemailer \
dockerinaction/ch2_agent
docker ps
#
docker run -d --name namespaceA \
busybox:1.29 /bin/sh -c "sleep 30000"
docker run -d --name namespaceB \
busybox:1.29 /bin/sh -c "nc -l 0.0.0.0 -p 80"
docker exec namespaceA ps
docker exec namespaceB ps
docker run --pid host busybox:1.29 ps
docker run -d --name webConflict nginx:latest
docker logs webConflict
docker exec webConflict nginx -g 'daemon off;'
# 解决方案
docker run -d --name webA nginx:latest
docker logs webA
docker run -d --name webB nginx:latest
docker logs webB
# 容器ID写入文件
CID=$(docker ps --latest --quiet)
echo $CID
CID=$(docker ps -l -q)
echo $CID
MAILER_CID=$(docker run -d dockerinaction/ch2_mailer)
WEB_CID=$(docker create nginx)
AGENT_CID=$(docker create --link $WEB_CID:insideweb \
--link $MAILER_CID:insidemailer \
dockerinaction/ch2_agent)
echo $MAILER_CID
echo $AGENT_CID
# wrong
docker start $AGENT_CID
docker start $WEB_CID
# right
docker start $WEB_CID
docker start $AGENT_CID
MAILER_CID=$(docker run -d dockerinaction/ch2_mailer)
WEB_CID=$(docker run -d nginx)
AGENT_CID=$(docker run -d \
--link $WEB_CID:insideweb \
--link $MAILER_CID:insidemailer \
dockerinaction/ch2_agent)
docker run -d --name wp --read-only wordpress:5.0.0-php7.2-apache
docker inspect --format "{{.State.Running}}" wp
docker logs wp
docker run -d --name wp_writable wordpress:5.0.0-php7.2-apache
docker container diff wp_writable
docker run -d --name wp2 --read-only -v /run/apache2/ --tmpfs /tmp wordpress:5.0.0-php7.2-apache
docker logs wp2
docker run -d --name wpdb -e MYSQL_ROOT_PASSWORD=ch2demo mysql:5.7
docker run -d --name wp3 --link wpdb:mysql -p 8000:80 --read-only -v /run/apache2/ --tmpfs /tmp wordpress:5.0.0-php7.2-apache
docker inspect --format "{{.State.Running}}" wp3
#!/bin/sh
DB_CID=$(docker create -e MYSQL_ROOT_PASSWORD=ch2demo mysql:5.7)
docker start $DB_CID
MAILER_CID=$(docker create dockerinaction/ch2_mailer)
docker start $MAILER_CID
WP_CID=$(docker create --link $DB_CID:mysql -p 80 \
--read-only -v /run/apache2/ --tmpfs /tmp \
wordpress:5.0.0-php7.2-apache)
docker start $WP_CID
AGENT_CID=$(docker create --link $WP_CID:insideweb \
--link $MAILER_CID:insidemailer \
dockerinaction/ch2_agent)
docker
#!/bin/sh
if [ ! -n "$CLIENT_ID" ]; then
echo "Client ID not set"
exit 1
fi
WP_CID=$(docker create \
--link $DB_CID:mysql \
--name wp_$CLIENT_ID \
-p 80 \
--read-only -v /run/apache2/ --tmpfs /tmp \
-e WORDPRESS_DB_NAME=$CLIENT_ID \
--read-only wordpress:5.0.0-php7.2-apache)
docker start $WP_CID
AGENT_CID=$(docker create \
--name agent_$CLIENT_ID \
--link $WP_CID:insideweb \
--link $MAILER_CID:insidemailer \
dockerinaction/ch2_agent)
docker start $AGENT_CID
# 容器的状态和依赖
# 清理
docker rm -vf $(docker ps -a -q)
题外话:3句话的魅力
docker create --name mysql_data_container \
-v /var/lib/mysql ubuntu
docker run --volumes-from mysql_data_container \
-v /var/lib/mysql:/var/lib/mysql \
-e MYSQL_USER=mysql \
-e MYSQL_PASSWORD=mysql \
-e MYSQL_DATABASE=test \
-e MYSQL_ROOT_PASSWORD=test -it \
-p 3306:3306 \
-d mysql
docker run -d \
--name wordpress \
--link mysql:mysql \
wordpress
可能 容器id小问题
命令小结
docker images
docker search nginx
docker run -d --name xxx1 nginx
docker run -it --name xxx2 nginx
docker run --link original_container_name:new_name xxx # 允许link多个
docker ps
docker ps -a
docker restart xxx
docker stop xxxx
docker logs xxx
Docker In Action 学习笔记 根据第二版有所更新的更多相关文章
- 《Java学习笔记(第8版)》学习指导
<Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多 ...
- 红帽学习笔记[RHCSA] 第二周
目录 红帽学习笔记[RHCSA]第二周 环境 第七课[网络配置相关] 在Vmware中添加网卡 将网卡添加到虚拟机上 关于网卡命名规则 配置网络 网络配置命令总结 更改hostname 关于SSH的一 ...
- Stealth视频教程学习笔记(第二章)
Stealth视频教程学习笔记(第二章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提 ...
- 【web开发学习笔记】Structs2 Action学习笔记(两)
action学习笔记2-大约action method讨论 Action运行的时候并不一定要运行execute方法,能够在配置文件里配置Action的时候用method=来指定运行哪个方法 也能够在u ...
- Docker Image管理学习笔记,ZT
Docker Image管理学习笔记 http://blog.csdn.net/junjun16818/article/details/38423391
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画 学习目标 熟悉蒙皮动画的术语: 学习网格层级变换 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS)
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS) 学习目标 回顾复数,以及 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION)
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION) 学习目标 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图 本章介绍一种在游戏和应用中,模拟动态阴影的基本阴影 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
随机推荐
- SICP 笔记:环境配置
SICP 笔记:环境配置 记录学习<算机的程序的构造和解释>的笔记. 环境配置 SICP 里面使用的语言是一种 Lisp 的变体 Scheme. 使用 DrRacket 作为 IDE 来进 ...
- mount无响应
mount -t xfs /dev/sdb /data 挂载不成功,且命令无任何回显. dmesg 查看到有报错 tailf /var/log/messages -n 100 systemctl da ...
- Centos+django+uwsgi+python 环境搭建
首先需要具备linux的基本操作. centos 6.x 版本默认安装的 python 版本为2.x 输入: [root@dev ~]# python -VPython 2.6.6 下面装一些用到的库 ...
- sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf
sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf sap IUT255 Integration of SAP CRM and ...
- SQLSERVER 根据一个库的视图在另一个库中生成一张表
select * into VPsiOuntStockBill from [KshDbPro].dbo.VPsiOuntStockBill
- js两个数组对象中,获取不相同的值 非交集元素对象
查看前端面试题小程序 大量面试题和答案,请微信查看 var array1 = [ {"Num": "A " },{"Num": " ...
- Vue全局方法配置
在Vue项目开发中,肯定会有这样一个场景:在不同的组件页面用到同样的方法,比如格式化时间,文件下载,对象深拷贝,返回数据类型,复制文本等等.这时候我们就需要把常用函数抽离出来,提供给全局使用.那如何才 ...
- iOS开发之检测项目是否包含UIWebView
应苹果审核要求不能包含UIWebView,所以我们上线之前应该扫一下项目是否包含UIWebView 我们直接打开终端 cd 到工程文件下面 执行命令 grep -r UIWebView . 在扫描结 ...
- 检测sqlserver数据库是否能远程连通
建立一个.udl的文件夹,双击打开.输入相关的连接字符串点击测试即可.
- CentOS 7.9 环境下部署 MySQL 5.7 服务
sudo setenforce Permissive sudo vi /etc/selinux/config SELINUX=permissive sudo systemctl stop firewa ...