docker 结合shell使用方法,让你更理解docker的运行顺序

docker run -itd \                     #不多解释,-itd带交互后台运行

--name cdg\                           #容器名称

python\                                   #镜像名称

/bin/bash -c \                           #运行bash shell -c执行后面脚本

"touch /1.py;\                           #在根目录touch一个1.py文件

echo -e 'import requests\nr=requests.get(\"http://www.baidu.com\")\nprint(r.text)'>>/1.py ;\

#数据追加到容器根目录的1.py

pip3 install requests;\ #pip安装requests库

python /1.py;\             #运行1.py

sleep 100s"                #等待100后容器退出

注:docker 命令是顺序运行

注:echo -e 带参数代表遇到  \n 转义,但是遇到字符串也会转义,所以后面地址要加斜杠  requests.get(\"http://www.baidu.com\")

你可能感兴趣的:(docker,linux,运维)