2017-06-14 54 views
1

組成泊塢窗文件後,一切都建立很好,但做docker ps 後,也沒有任何的容器正在運行。無法打開應用程序後,搬運工,譜寫

下面是我docker-compose.yml

version: '3' 
services: 
    web-app: 
    build: 
     context: . 
     dockerfile: web-app/Dockerfile 
    ports: 
     - 8080:8080 
    links: 
     - app-db 

    app-db: 
    build: 
     context: . 
     dockerfile: app-db/Dockerfile 

    environment: 
    - MYSQL_ROOT_PASSWORD=password 
    - MYSQL_DATABASE=Optimize 
    ports: 
     - 3306:3306 

Dockerfile web應用程序就像是

FROM aallam/oracle-java 

ENV DEBIAN_FRONTEND noninteractive 
ENV TOMCAT_MAJOR_VERSION=8 
ENV TOMCAT_VERSION=8.5.14 
ENV TOMCAT_HOME=/opt/tomcat 

RUN apt-get update && \ 
    rm -rf /var/lib/apt/lists/* 

WORKDIR /tmp 

RUN groupadd tomcat && \ 
    useradd -s /bin/false -g tomcat -d $TOMCAT_HOME tomcat && \ 
    mkdir $TOMCAT_HOME && \ 
    #wget http://mirrors.standaloneinstaller.com/apache/tomcat/tomcat-$TOMCAT_MAJOR_VERSION/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz && \ 
    wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz && \ 
    tar xzvf apache-tomcat-8*tar.gz -C $TOMCAT_HOME --strip-components=1 && \ 
    chown -R tomcat:tomcat $TOMCAT_HOME && \ 
    chmod -R g+r $TOMCAT_HOME/conf && \ 
    chmod g+x $TOMCAT_HOME/conf && \ 
    rm -rf apache-tomcat-$TOMCAT_VERSION.tar.gz 

WORKDIR/

ADD /web-app/tomcat-run.sh /tomcat-run.sh 
ADD /web-app/run.sh /run.sh 
ADD /web-app/supervisord-tomcat.conf /etc/supervisor/conf.d/supervisord-tomcat.conf 
ADD /web-app/settings.xml $TOMCAT_HOME/conf/settings.xml 
ADD /web-app/tomcat-users.xml $TOMCAT_HOME/conf/tomcat-users.xml 
ADD /web-app/context.xml $TOMCAT_HOME/webapps/manager/META-INF/context.xml 
RUN chmod 755 /*.sh 

COPY /web-app/target/*.war $TOMCAT_HOME/webapps/ 

expose 8080 
ENTRYPOINT ["/run.sh"] 

Dockerfile的數據庫就像

FROM aallam/oracle-java 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update && \ 
    apt-get -yq install mysql-server supervisor && \ 
    rm -rf /var/lib/apt/lists/* 

#WORKDIR/
ADD /app-db/bind_0.cnf /etc/mysql/conf.d/bind_0.cnf 
ADD /app-db/mysql-run.sh /mysql-run.sh 
ADD /app-db/supervisord-mysql.conf /etc/supervisor/conf.d/supervisord-mysql.conf 

VOLUME ["/var/lib/mysql"] 
expose 3306 

docker-compose up -d後,這是輸出在終端

[email protected]:~/Creating optdocker_app-db_1

[email protected]:~/Creating optdocker_web-app_1

加入docker-compose logsnetstat -tln

[email protected]:~/Opt-Docker$ netstat -tln 
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address   Foreign Address   State  
tcp  0  0 127.0.0.1:5432   0.0.0.0:*    LISTEN  
tcp  0  0 127.0.0.1:25   0.0.0.0:*    LISTEN  
tcp  0  0 127.0.0.1:32000   0.0.0.0:*    LISTEN  
tcp  0  0 0.0.0.0:10000   0.0.0.0:*    LISTEN  
tcp  0  0 0.0.0.0:80    0.0.0.0:*    LISTEN  
tcp  0  0 127.0.1.1:53   0.0.0.0:*    LISTEN  
tcp6  0  0 ::1:25     :::*     LISTEN  
tcp6  0  0 :::40645    :::*     LISTEN  
tcp6  0  0 127.0.0.1:9000   :::*     LISTEN  
tcp6  0  0 127.0.0.1:9001   :::*     LISTEN  
tcp6  0  0 :::10000    :::*     LISTEN  
tcp6  0  0 127.0.0.1:36241   :::*     LISTEN  
tcp6  0  0 :::42801    :::*     LISTEN  
tcp6  0  0 :::37971    :::*     LISTEN  
[email protected]:~/Opt-Docker$ docker-compose logs 
Attaching to optdocker_web-app_1, optdocker_app-db_1 
[email protected]:~/Opt-Docker$ 

docker ps不給任何東西。誰能告訴在哪裏和什麼我做錯了

docker ps -a輸出

CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS      PORTS    NAMES 
3a93140ab6f4  optdocker_web-app "/bin/bash"   16 minutes ago  Exited (0) 16 minutes ago      optdocker_web-app_1 
53b7ec265fac  optdocker_app-db "/bin/bash"   16 minutes ago  Exited (0) 16 minutes ago      optdocker_app-db_1 
+0

你可以添加一些日誌或輸出? – javasenior

+0

而且可以肯定的是3306端口沒有被任何應用程序。 – javasenior

+0

你的意思是'docker-compose logs'? –

回答

0

更新Dockerfileweb應用程序這樣的:

FROM aallam/oracle-java 

ENV DEBIAN_FRONTEND noninteractive 
ENV TOMCAT_MAJOR_VERSION=8 
ENV TOMCAT_VERSION=8.5.14 
ENV TOMCAT_HOME=/opt/tomcat 

RUN apt-get update && \ 
apt-get -yq install supervisor && \ 
    rm -rf /var/lib/apt/lists/* 

WORKDIR /tmp 

RUN groupadd tomcat && \ 
    useradd -s /bin/false -g tomcat -d $TOMCAT_HOME tomcat && \ 
    mkdir $TOMCAT_HOME && \ 
    #wget http://mirrors.standaloneinstaller.com/apache/tomcat/tomcat-$TOMCAT_MAJOR_VERSION/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz && \ 
    wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz && \ 
    tar xzvf apache-tomcat-8*tar.gz -C $TOMCAT_HOME --strip-components=1 && \ 
    chown -R tomcat:tomcat $TOMCAT_HOME && \ 
    chmod -R g+r $TOMCAT_HOME/conf && \ 
    chmod g+x $TOMCAT_HOME/conf && \ 
    rm -rf apache-tomcat-$TOMCAT_VERSION.tar.gz 

WORKDIR/

ADD /web-app/tomcat-run.sh /tomcat-run.sh 
ADD /web-app/run.sh /run.sh 
ADD /web-app/supervisord-tomcat.conf /etc/supervisor/conf.d/supervisord-tomcat.conf 
ADD /web-app/settings.xml $TOMCAT_HOME/conf/settings.xml 
ADD /web-app/tomcat-users.xml $TOMCAT_HOME/conf/tomcat-users.xml 
ADD /web-app/context.xml $TOMCAT_HOME/webapps/manager/META-INF/context.xml 
RUN chmod 755 /*.sh 

COPY /web-app/target/*.war $TOMCAT_HOME/webapps/ 

expose 8080 
ENTRYPOINT ["/run.sh"] 

重複run.sh兩個web應用程序APP-DB文件夾。

更新DockerfileAPP-分貝這樣的:

FROM aallam/oracle-java 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update && \ 
    apt-get -yq install mysql-server supervisor && \ 
    rm -rf /var/lib/apt/lists/* 

#WORKDIR/
ADD /app-db/run.sh /run.sh 
ADD /app-db/bind_0.cnf /etc/mysql/conf.d/bind_0.cnf 
ADD /app-db/mysql-run.sh /mysql-run.sh 
ADD /app-db/supervisord-mysql.conf /etc/supervisor/conf.d/supervisord-mysql.conf 

VOLUME ["/var/lib/mysql"] 
expose 3306 
ENTRYPOINT ["/run.sh"] 

然後運行命令:

docker-compose up 
docker ps 

輸出會是這樣並且系統啓動:

CONTAINER ID  IMAGE    COMMAND    CREATED     STATUS    PORTS     NAMES 
a60682b914a4  test_web-app  "/run.sh"   Less than a second ago Up 9 seconds  0.0.0.0:8080->8080/tcp test_web-app_1 
607522cac623  test_app-db   "/run.sh"   Less than a second ago Up 9 seconds  0.0.0.0:3306->3306/tcp test_app-db_1 

連接MySQL小號erver在app-db容器,在你的項目中的JDBC連接URL應該是這樣的:

"jdbc:mysql://DOCKER_MACHINE_IP:3306/DB_NAME". 

APP-DB容器側,訪問MySQL命令行,創建並給予與DOCKER_MACHINE_IP用戶權限:

> CREATE USER 'root'@'DOCKER_MACHINE_IP' IDENTIFIED BY 'root_password'; 
> GRANT ALL ON *.* to [email protected]'DOCKER_MACHINE_IP' IDENTIFIED BY 'root_password'; 
> FLUSH PRIVILEGES; 
+0

的容器了,但我想它不是與MySQL連接[這裏是日誌(https://gist.github.com/Beanben/eb28d3084b9caf899728842d8c8980b5)有人能幫助我 –

+0

似乎項目目標文件夾下能在連接數據庫之前不會啓動。你可以添加catalina和localhost完整日誌嗎?還請檢查mysql是否有你想創建的數據庫。 – javasenior

+0

燁沒有數據庫,我想創造並請[點擊這裏登錄](https://gist.github.com/Beanben/d0b81b87ef787409e613223318eb86ac) –

相關問題