Графана на докере - контейнеры работают, но не выводятся в браузере, - PullRequest
0 голосов
/ 30 ноября 2018

Привет, ребята. Я создал startu.sh, Dockerfile и docker-compose.yml.

, когда я выполняю сборку «docker-compose», образ был успешно собран и когда я использую «docker-compose up»оба контейнера запущены и работают 1 mysql 2 grafana_web, но когда я запускаю свой публичный ip с портом, нет вывода.пожалуйста помогите ..

файл docker-compose.yml

version: '3'
services:
   web:
      build: .
      container_name: grafana
      ports:
        - "3000:3000"
      expose:
        - 3000
      volumes:
        - .:/newvolebs
      networks:
        - overlay
      environment:
         MYSQL_HOST: mysql
         MYSQL_DATABASE: grafana
         MYSQL_USERNAME: root
         MYSQL_PASSWORD: dashboard@123
   mysql:
      image: mysql:5.6
      ports:
        - "3306:3306"
      expose:
        - 3306
      volumes:
        - newvolebs:/var/lib/mysql
      networks:
        - overlay
      environment:
        MYSQL_ROOT_PASSWORD: dashboard@123
        MYSQL_DATABASE: grafana
volumes:
 newvolebs:
   driver: local
networks:
 overlay:
   driver: "bridge"

и мой файл Docker

FROM centos:centos7
RUN     yum -y update \

    && yum --setopt=tsflags=nodocs -y install \

    gcc-c++ make \wget \

    httpd \git \

    mod_ssl \tar && \

    yum clean all && \

    yum install -y sudo && \

    adduser centos && \

    echo "centos ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user
    #USER centos
    EXPOSE  3000
    COPY startup.sh /usr/local/bin/
    RUN echo "[main_settings]" > /var/www/html/config.ini \

&& echo "headerTitle='QTDashboard'" >> /var/www/html/config.ini \

&& echo "encryptKey='bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3'" >> /var/www/html/config.ini \



&& echo ";Timezone Setting. ex: 'America/New_York'" >> /var/www/html/config.ini \

&& echo "defaultTimezone=''" >> /var/www/html/config.ini \



&& echo ";Database parameters for system usage (Should not be used by custom dashboard/charts)" >> /var/www/html/config.ini \

&& echo "dashboardDatabaseServer=mysql" >> /var/www/html/config.ini \

&& echo "dashboardDatabaseName=qtdashboard" >> /var/www/html/config.ini \

&& echo "dashboardDatabaseUserName=root" >> /var/www/html/config.ini \

&& echo "dashboardDatabasePassword=12345678" >> /var/www/html/config.ini \



&& echo ";grafana credentials" >> /var/www/html/config.ini \

&& echo "grafanaDatabaseServer=mysql" >> /var/www/html/config.ini \

&& echo "grafanaDatabaseName=grafana" >> /var/www/html/config.ini \

&& echo "grafanaDatabaseUserName=root" >> /var/www/html/config.ini \

&& echo "grafanaDatabasePassword=12345678" >> /var/www/html/config.ini
WORKDIR  /root
CMD bash /usr/local/bin/startup.sh

, а мой файл startup.sh -

#!/bin/bash

 log "Installing Go language"

 VERSION="1.9.3"

  HOME="/home/$USER"



 if [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then

# assume Zsh

shell_profile="zshrc"

   elif [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then

# assume Bash

shell_profile="bashrc"

   fi



     PROCESS="--64"



         if [ "$PROCESS" == "--32" ]; then

     DFILE="go$VERSION.linux-386.tar.gz"

  elif [ "$PROCESS" == "--64" ]; then

DFILE="go$VERSION.linux-amd64.tar.gz"

  elif [ "$PROCESS" == "--remove" ]; then

   rm -rf "$HOME/.go/"

sed -i '/# GoLang/d' "$HOME/.${shell_profile}"

sed -i '/export GOROOT/d' "$HOME/.${shell_profile}"

sed -i '/:$GOROOT/d' "$HOME/.${shell_profile}"

sed -i '/export GOPATH/d' "$HOME/.${shell_profile}"

sed -i '/:$GOPATH/d' "$HOME/.${shell_profile}"

echo "Go removed."

exit 0

   elif [ "$PROCESS" == "--help" ]; then

   #print_help

     exit 0

        else

      #print_help

      exit 1

  fi



      if [ -d "$HOME/gocode" ] || [ -d "$HOME/go" ]; then

     echo "The 'go' or 'gocode' directories already exist. Exiting."

     else

       echo "Downloading $DFILE ..."

     wget https://storage.googleapis.com/golang/$DFILE -O /tmp/go.tar.gz



         if [ $? -ne 0 ]; then

           echo "Download failed! Exiting."

       exit 1

       fi



           echo "Extracting File..."

      tar -C "$HOME" -xzf /tmp/go.tar.gz

          mv "$HOME/go" "$HOME/gocode"

        touch "$HOME/.${shell_profile}"

         {

            echo '# GoLang'

            echo 'export GOROOT=$HOME/gocode'

             echo 'export PATH=$PATH:$GOROOT/bin'

              echo 'export GOPATH=$HOME/go'

             echo 'export PATH=$PATH:$GOPATH/bin'

                         } >> "$HOME/.${shell_profile}"



                  mkdir -p $HOME/go/{src,pkg,bin}

              echo -e "\nGo $VERSION was installed.\nMake sure to relogin 
               into your shell or run:"

               echo -e "\n\tsource $HOME/.${shell_profile}\n\nto update your 
          environment variables."

                 echo "Tip: Opening a new terminal window usually just 
                  works. :)"

            #source $HOME/.${shell_profile}

              rm -f /tmp/go.tar.gz

              fi



                  #source $HOME/.$shell_profile

                  source /home/$USER/.bashrc



                       #SCRIPT FOR INSTALLING NODEJS AND GRAFANA

              echo  "Installing Grafana"

                   echo  "Downloading NodeJS - Dependency for Grafana"

                 if ! [ -x "$(command -v node)" ]; then

                   curl --silent --location 
                          https://rpm.nodesource.com/setup_9.x | sudo bash

                  sudo yum -y install nodejs

                         else

                    echo "Node Already Exist"

                          fi



                if ! [ -x "$(command -v gcc)" ]; then

                  sudo yum install gcc-c++ make

                  else

                 echo "GCC Already Exist"

                      fi



             echo "Pulling the file for GRAFANA. Please wait....."

                cd $GOPATH/src

               go get github.com/grafana/grafana



                echo "Building the Backend with xxxxxxxxxx"

                cd $GOPATH/src/github.com/grafana/grafana

              sed -i 










  's#https://github.com/grafana/grafana#https://gitlab.com//xxxxxxxxx.git#g' 
          $GOPATH/src/github.com/grafana/grafana/.git/config

              git checkout -b grafanav2

         git pull origin grafanav2



       #CREATING CONGIG FILE FOR GRAFANA IN MYSQL

               CONFIGDIR="$GOPATH/src/github.com/grafana/grafana/conf"



      echo "#################################### Database 
              ####################################

            [database]

            # You can configure the database connection by specifying type, 
        host, name, user and password

      # as separate properties or as on string using the url properties.



             # Either mysql, postgres or sqlite3, it's your choice

   ;type = sqlite3

   ;host = 127.0.0.1:3306

        ;name = grafana

       ;user = root

           # If the password contains # or ; you have to wrap it with triple 
             quotes. Ex#password

               ;password =



            # Use either URL or the previous fields to configure the 
           database

       # Example: mysql://user:secret@host:port/database

             url =  mysql://root:12345678@localhost:3306/grafana



         # For postgres only, either disable, require or verify-full

           ;ssl_mode = disable



             # For sqlite3 only, path relative to data_path setting

           ;path = grafana.db



     #Max idle conn setting default is 2

          ;max_idle_conn = 2



            # Max conn setting default is 0 (mean not set)

        ;max_open_conn =



         # Connection Max Lifetime default is 14400 (means 14400 seconds or 
            4 hours)

         ;conn_max_lifetime = 14400



              # Set to true to log the sql calls and execution times.

             log_queries =" > $CONFIGDIR/custom.ini



            if ! echo -e $CONFIGDIR/custom.ini; then

          echo "Grafana Config file wasn't created !"

             else

            echo "Grafana Config file created !"

                fi



               #Creation of config file ends here

             cd $GOPATH/src/github.com/grafana/grafana



            echo "Setup an build grafana"

              go run build.go setup

                     go run build.go build



                echo "Build the frontend assets"

      sudo npm install -g yarn

         yarn install --pure-lockfile

         nohup sudo npm run watch &



           echo "!!! INSTALLATION DONE FOR GRAFANA !!!!"

         echo "Restarting the grafana server"

            sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT 
            --to-port 3000

         cd $GOPATH/src/github.com/grafana/grafana/bin/

       grafana-server
...