gpt4 book ai didi

docker - 使用Ansible来配置Docker容器

转载 作者:行者123 更新时间:2023-12-02 19:11:43 27 4
gpt4 key购买 nike

嗨,我正在使用下面的docker文件构建镜像。它运行的Maven玩书完美无缺,但是当开始运行声纳玩书时,它就挂起了,什么也没发生。只有声纳书有重新启动语句才是玩书中的不足之处。这可能是问题的原因。我已经测试了每本剧本,并且每本在内部完美运行容器。
有什么办法可以同时查看容器日志和构建镜像时所有Ansible所做的事情。到目前为止,Docker仅在一步完成后才吐出日志。

FROM xyz.com/akathaku/cidemo:latest

MAINTAINER akathaku <akathaku@gmail.com>

USER root


ENV SCPATH /etc/supervisor/conf.d
ENV PLAYBOOKS /ansible

# RUN yum -y update

# The daemons
RUN yum -y install supervisor
RUN mkdir -p /var/log/supervisor

# Supervisor Configuration
ADD ./supervisord/conf.d/* $SCPATH/

#Running ansible
ADD ./sonar-playbook $PLAYBOOKS/sonar-playbook
ADD ./maven-playbook $PLAYBOOKS/maven-playbook
ADD ./jenkins-playbook $PLAYBOOKS/jenkins-playbook
ADD ./tomcat-playbook $PLAYBOOKS/tomcat-playbook

WORKDIR $PLAYBOOKS
RUN ansible-playbook $PLAYBOOKS/sonar-playbook/sonar.yml -c local
RUN ansible-playbook $PLAYBOOKS/maven-playbook/maven.yml -c local
RUN ansible-playbook $PLAYBOOKS/jenkins-playbook/jenkins.yml -c local
RUN ansible-playbook $PLAYBOOKS/tomcat-playbook/tomcat.yml -c local


# Application Code

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisor.conf"]
EXPOSE 8080 8081 9000 9001 8086

以下是docker run 的输出
Step 1 : FROM xyz.com/akathaku/cidemo:latest
---> d477ceab5d3b
Step 2 : MAINTAINER akathaku <akathaku@gmail.com>
---> Using cache
---> a9c3c191aabd
Step 3 : USER root
---> Using cache
---> 24a18ddc6f49
Step 4 : ENV SCPATH /etc/supervisor/conf.d
---> Using cache
---> ea6f4dada89c
Step 5 : ENV PLAYBOOKS /ansible
---> Using cache
---> 9d42760dc51f
Step 6 : RUN yum -y install supervisor
---> Using cache
---> 7af486ce2a8c
Step 7 : RUN mkdir -p /var/log/supervisor
---> Using cache
---> a1b1c145d490
Step 8 : ADD ./supervisord/conf.d/* $SCPATH/
---> Using cache
---> f16e32135351
Step 9 : ADD ./sonar-playbook $PLAYBOOKS/sonar-playbook
---> 170c1dc82ffa
Removing intermediate container bfa474ef9d11
Step 10 : ADD ./maven-playbook $PLAYBOOKS/maven-playbook
---> 90a57735fe3b
Removing intermediate container b5f7bbb3b85d
Step 11 : ADD ./jenkins-playbook $PLAYBOOKS/jenkins-playbook
---> 09ab0f929f45
Removing intermediate container 7dc62423354d
Step 12 : ADD ./tomcat-playbook $PLAYBOOKS/tomcat-playbook
---> 13c3bb5f7aca
Removing intermediate container 4356605f503a
Step 13 : WORKDIR $PLAYBOOKS/maven-playbook
---> Running in 34867677f4e1
---> f48ffe4115db
Removing intermediate container 34867677f4e1
Step 14 : RUN ansible-playbook maven.yml -c local
---> Running in 4eda53bf7e00

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [maven | Install Java 1.8 JRE] ******************************************
changed: [localhost]

TASK: [maven | Install Java 1.8 JDK] ******************************************
changed: [localhost]

TASK: [maven | lineinfile dest='/etc/profile' regexp='^#?\s*export JAVA_HOME=(.*)$' line='export JAVA_HOME=/usr/lib/jvm/java-openjdk' state=present] ***
changed: [localhost]

TASK: [maven | lineinfile dest=/etc/profile regexp='^#?\s*export PATH=(.*)JAVA_HOME(.*)$' line="export PATH=$PATH:$JAVA_HOME/bin" state=present] ***
changed: [localhost]

TASK: [maven | Reload profile] ************************************************
changed: [localhost]

TASK: [maven | Download Apache Maven] *****************************************
changed: [localhost]

TASK: [maven | Untar Maven to /opt] *******************************************
changed: [localhost]

TASK: [maven | Create symbolic link maven to the /opt/apache-{{ maven_version }}] ***
changed: [localhost]

TASK: [maven | lineinfile dest=/etc/profile regexp='^#?\s*export MAVEN_HOME=(.*)$' line='export MAVEN_HOME=/opt/maven' state=present] ***
changed: [localhost]

TASK: [maven | lineinfile dest=/etc/profile regexp='^#?\s*export PATH=(.*)MAVEN_HOME(.*)$' line="export PATH=$PATH:$MAVEN_HOME/bin" state=present] ***
changed: [localhost]

TASK: [maven | Reload profile] ************************************************
changed: [localhost]

TASK: [maven | Create local repository] ***************************************
changed: [localhost]

TASK: [maven | Creates setting.xml file] **************************************
changed: [localhost]

PLAY RECAP ********************************************************************
localhost : ok=14 changed=13 unreachable=0 failed=0

---> fb211f3fbbfd
Removing intermediate container 4eda53bf7e00
Step 15 : WORKDIR $PLAYBOOKS/sonar-playbook
---> Running in b9ba0623b48a
---> d48ad5abbf43
Removing intermediate container b9ba0623b48a
Step 16 : RUN ansible-playbook sonar.yml -c local
---> Running in 2d2716354c5d

最佳答案

您可以执行以下操作:

从挂起的行注释掉dockerfile直到结尾。

构建镜像,以交互方式启动新容器,然后直接从 shell 运行同一行。这基本上等于让它在docker构建期间运行,只有您才有机会检查一下这台机器上发生的一切(您可以拖尾日志,可以在挂起容器时将docker exec放入容器中,并确定哪个进程卡住了,等等。)。

关于docker - 使用Ansible来配置Docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35335024/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com