简体   繁体   English

使用Ansible来配置Docker容器

[英]using ansible for provisioning docker containers

Hi am using below docker file to build an image. 您好,我正在使用下面的docker文件构建映像。 Its running maven playbook perfectly But when started running sonar play book it gets hanged and nothing happens.Only dffrence in playbooks are that sonar playbook has restart statements.Can it a reason for the problem.I have tested each playbook and each one runs perfectly inside the container. 它运行的Maven手册完美无缺,但是当开始运行声纳手册时,它会挂起并且什么也没有发生。只有在手册中不同的是,声纳手册具有重新启动语句。这可能是问题的原因。我已经测试了每本手册,并且每本在内部完美运行容器。 Is ther any way to see container logs side by side as what all ansible is doing when building the image.As of now Docker spits logs only when its done with a step. 有什么办法可以同时查看容器日志和构建映像时所有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

Below is the output of docker run 以下是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

Here's what you can do: 您可以执行以下操作:

Comment out the dockerfile from the line that hangs until the end. 从挂起的行注释掉dockerfile直到结尾。

Build the image, start a new container interactively and then run the same line directly from the shell. 构建映像,以交互方式启动新容器,然后直接从外壳运行同一行。 This is basically equivalent to letting it run during docker build, only you'd get a chance to also inspect whatever's happening on that machine (you could tail logs, you could docker exec into the container while it's hanging and figure out which process is stuck, etc.). 这基本上等于让它在docker构建期间运行,只有您才有机会也检查一下该机器上发生的一切(可以拖尾日志,可以在容器挂起时将docker exec放入容器中并找出哪个进程卡住了等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM