我需要在我的shell脚本中知道一些docker exec命令的输出,例如我有一个nginx容器,在我的脚本中运行:
docker exec -it containerName /etc/init.d/nginx configtest
我想仅在nginx配置测试成功时才继续执行脚本,而不是在失败时.
我已经尝试使用$?,但它0甚至然后configtest输出失败(因为我理解的docker exec成功执行).
有我的Dockerfile:
# https://hub.docker.com/_/php/
FROM php:5.5.23-fpm
USER www-data
ADD .bash_profile /var/www/.bash_profile
SHELL ["/bin/bash", "-c"]
RUN source /var/www/.bash_profile
Run Code Online (Sandbox Code Playgroud)
然后,在构建容器后,我运行了docker exec -it CONTAINER_NAME bash,但没有看到定义为的别名/var/www/.bash_profile。但是,如果我source /var/www/.bash_profile手动执行–一切正常。
这里描述了相同的问题:https://github.com/docker/kitematic/issues/896,但没有答案。