#/bin/bash
# 初始化变量
image="ubuntu:22.04"
command="bash"
container_name="mycontainer"
# 解析命令行参数
while getopts "i:c:n:" opt; do
case $opt in
i)
image="$OPTARG"
;;
c)
command="$OPTARG"
;;
n)
container_name="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [ "$(docker ps | grep ${container_name})" == "" ];then
docker run -it -d --name ${container_name} -v `pwd`:/playground ${image} ${command}
echo "created a contrainer ${container_name}"
fi
echo "go into the container ${container_name}"
docker exec -it ${container_name} ${command}
方便创建/进入docker容器的简单脚本
最新推荐文章于 2024-09-13 15:41:28 发布