我天真地期望这个命令在一个正在运行的容器中运行bash shell:
docker run "id of running container" /bin/bash
看起来是不可能的,我得到了一个错误:
2013/07/27 20:00:24 Internal server error: 404 trying to fetch remote history for 27d757283842
因此,如果我想在运行容器中运行bash shell(例如用于诊断目的)
我必须在里面运行SSH服务器并通过SSH登录吗?
这是我的解决方案
在Dockerfile中:
# ...
RUN mkdir -p /opt
ADD initd.sh /opt/
RUN chmod +x /opt/initd.sh
ENTRYPOINT ["/opt/initd.sh"]
在initd.sh文件中
#!/bin/bash
...
/etc/init.d/gearman-job-server start
/etc/init.d/supervisor start
#very important!!!
/bin/bash
镜像构建后,你有两个选择使用exec或attach:
使用exec(首选)并运行:
——name $CONTAINER_NAME -dt $IMAGE_NAME
然后
- $CONTAINER_NAME /bin/bash
并使用CTRL + D分离
使用attach并运行:
——name $CONTAINER_NAME -dit $IMAGE_NAME
然后
附加$CONTAINER_NAME
并使用CTRL + P和CTRL + Q分离
注意:选项之间的区别是参数-i