2

After composing docker file, everything builds fine but after doing docker ps it shows no containers are running.

Below is my 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

and Dockerfile for web-app is like

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"]

and the Dockerfile for database for is like

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

after docker-compose up -d this was the output in the terminal

user@ubuntu:~/Creating optdocker_app-db_1

user@ubuntu:~/Creating optdocker_web-app_1

adding docker-compose logs and netstat -tln

user@ubuntu:~/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     
user@ubuntu:~/Opt-Docker$ docker-compose logs
Attaching to optdocker_web-app_1, optdocker_app-db_1
user@ubuntu:~/Opt-Docker$ 

but docker ps doesn't give anything. can anyone tell where and what i am doing wrong

docker ps -a output

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
Community
  • 1
  • 1
Prateek Naik
  • 2,522
  • 4
  • 18
  • 38

1 Answers1

0

Update Dockerfile in web-app like this:

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"]

Duplicate run.sh for both web-app and app-db folder.

Update Dockerfile in app-db like this:

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"]

Then run commands:

docker-compose up
docker ps 

Output will be like this and system is up:

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

To connect MySQL server in app-db container, your JDBC connection url in your project should be something like this:

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

At the app-db container side, access MySQL from command line, create and give permissions for user with DOCKER_MACHINE_IP:

> CREATE USER 'root'@'DOCKER_MACHINE_IP' IDENTIFIED BY 'root_password'; 
> GRANT ALL ON *.* to root@'DOCKER_MACHINE_IP' IDENTIFIED BY 'root_password';
> FLUSH PRIVILEGES;
javasenior
  • 1,786
  • 2
  • 22
  • 26
  • The containers are up but i guess its not connecting with the MySQL [here are the logs](https://gist.github.com/Beanben/eb28d3084b9caf899728842d8c8980b5) can anyone help me – Prateek Naik Jun 14 '17 at 16:35
  • It seems project under target folder can't start before connecting database. Can you add catalina and localhost full logs? Also please check whether mysql has the database you want to create. – javasenior Jun 15 '17 at 07:45
  • Yup there is no database which i wanted to create and also please find the [logs here](https://gist.github.com/Beanben/d0b81b87ef787409e613223318eb86ac) – Prateek Naik Jun 15 '17 at 10:23
  • Deploying process look like healthy. SEVERE logs are related with https://stackoverflow.com/questions/24850091 and https://stackoverflow.com/questions/3320400. – javasenior Jun 15 '17 at 11:27
  • I edit the answer for accessing MySQL from application. – javasenior Jun 15 '17 at 11:33
  • after implementing your solution getting this error `ERROR: for app-db Cannot start service app-db: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/run.sh\": permission denied"` – Prateek Naik Jun 15 '17 at 12:04
  • did you give permissions from MySQL? – javasenior Jun 15 '17 at 12:06