docker(常见调试技巧):docker打包镜像调试技巧
写Dockerfile可以先不指定CMD、ENTRYPOINT等启动命令,只要拷贝就好了
如下:
# Dockerfile for basic-app-client # Build with: # docker build -t basic-app-client:1.2.2-jdk7 . # Run with: # docker run -di --name basic-app-client basic-std-etl-client:1.2.2-jdk7 FROM openjdk:7-jre-alpine MAINTAINER haokailin <haokailin@umfintech.com> ENV VERSION 1.2.2 RUN \ echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories && \ echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories && \ apk update upgrade && \ apk add --no-cache procps curl bash && \ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone ADD app /usr/mpsp/app #CMD ["/usr/mpsp/app/script/serv.sh","console"]
先注释掉CMD启动命令,打包镜像app,然后用sh命令启动并进入容器,
docker run -ti basic-app-client:1.2.2.2-jdk7 sh # 进入容器后,再执行启动脚本,调试。
进入容器后,再启动应用的启动脚本,调试即可。
非常适用于docker log日志查看报错信息 不明确的情况,
如 exec user process caused "no such file or directory,这种报错。