为什么一个linux命令在conatiner中工作但在entrpoint.sh中没有

时间:2018-03-29 10:08:22

标签: linux docker entry-point docker-entrypoint

我使用的是ubuntu 16.04操作系统作为虚拟机。

在创建容器时,我在entrpoint.sh中有一些命令没有工作或表现得如预期的那样但当我在容器内手动运行时,同样的命令正在工作,确切地说下面是我的简单linux cp 命令,以递归方式从源复制到目标,并解压缩命令。

在我的entrypoint.sh中,我有三个命令:

  cd /tmp/localization/Tpae7610
  unzip \*.zip
  cp -r /tmp/localization/Tpae7610/*  /home/db2inst1/maximo/

当容器启动时,最后两个命令不起作用,当我说它不起作用时意味着它没有给出任何错误,但没有按预期将源内容复制到目标,也没有解压缩.zip文件

注意:但是当我在容器内手动运行时,同样的命令按预期工作。

entrypoint.sh

#!/bin/bash
sysctl -w kernel.shmmni=1024
sysctl -w kernel.shmall=2097152
sysctl -w kernel.msgmnb=65536
sysctl -w kernel.msgmax=65536
sysctl -w kernel.msgmni=4096
sysctl -w kernel.shmmax=4294967296

#set -e
#
#   Initialize DB2 instance in a Docker container
#
# # Authors:
#   * 
#
# 
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
mkdir -p /db2fs
chown db2inst1:db2iadm1 /db2fs
chmod -R 755 /db2fs

#cp /tmp/maxinst.sh /home/db2inst1/maximo/Maximo-7.6-CD/tools/maximo/maxinst.sh

if [ -z "$DB2INST1_PASSWORD" ]; then
  echo ""
  echo >&2 'error: DB2INST1_PASSWORD not set'
  echo >&2 'Did you forget to add -e DB2INST1_PASSWORD=... ?'
  exit 1
else
  echo "db2inst1:$DB2INST1_PASSWORD" | chpasswd
fi

if [ -z "$LICENSE" ];then
   echo ""
   echo >&2 'error: LICENSE not set'
   echo >&2 "Did you forget to add '-e LICENSE=accept' ?"
   exit 1
fi

if [ "${LICENSE}" != "accept" ];then
   echo ""
   echo >&2 "error: LICENSE not set to 'accept'"
   echo >&2 "Please set '-e LICENSE=accept' to accept License before use the DB2 software contained in this image."
   exit 1
fi

if [[ $1 = "db2start" ]]; then
    echo "Performing botc database start"
    if [ ! -d /db2fs/db2inst1 ]; then
      echo "Database location does not exist, creating database"
      chown -R db2inst1:db2iadm1 /maxdb7605
      chown -R db2inst1:db2iadm1 /home/db2inst1/maximo 
      find /maxdb7605 -type d -exec chmod 755 \{\} \;
      find /maxdb7605 -type f -exec chmod 644 \{\} \;
      cd /home/db2inst1/maximo
      #unzip -o tools.zip && rm tools.zip
      #unzip -o applications.zip && rm applications.zip 
      set -x 
      cd /home/db2inst1/maximo/tools
      if [ ! -f java ]; then
         ln -s /home/db2inst1/sqllib/java  java
      fi
      su - db2inst1 <<EOH
      db2start
      db2 create database maxdb76 on /db2fs dbpath on /db2fs using codeset UTF-8 territory us pagesize 32 K
      db2 connect to maxdb76
      db2 create bufferpool MAXBUFFPOOL pagesize 32K
      db2 grant connect on database to user maximo
      db2 GRANT DBADM,SECADM, CREATETAB,BINDADD,CONNECT,CREATE_NOT_FENCED_ROUTINE,IMPLICIT_SCHEMA,LOAD,CREATE_EXTERNAL_ROUTINE,QUIESCE_CONNECT ON DATABASE TO USER maximo
      db2 GRANT USAGE on WORKLOAD SYSDEFAULTUSERWORKLOAD TO USER maximo;
      db2 create schema maximo authorization maximo
      db2 create regular tablespace MAXDATA pagesize 32k managed by automatic storage extentsize 16 overhead 12.67 prefetchsize 16 transferrate 0.18 bufferpool MAXBUFFPOOL dropped table recovery on NO FILE SYSTEM CACHING
      db2 grant use of tablespace MAXDATA to user maximo
      db2 update db cfg using LOGFILSIZ 5000
      db2 update db cfg using LOGPRIMARY 50
      db2 update db cfg using LOGSECOND 50

      db2 connect reset
      db2stop force
      db2start

      cd /maxdb7605
      db2set DB2CODEPAGE=1208
      db2 connect to maxdb76
      db2 -t -f /maxdb7605/dbschema.sql
      db2 -t -f /maxdb7605/dev_grants.sql
      db2move maxdb76 LOAD -u maximo -p maximo -l lobs
      db2 connect to maxdb76 user maximo using maximo
      db2 -x "select 'values nextval for MAXIMO.',sequencename,';' from maxsequence" > /maxdb7605/sequence_update.sql
      db2 -t -f /maxdb7605/sequence_update.sql
      db2 connect reset
EOH
      rm -rf /maxdb7605

      set +x
      nohup /usr/sbin/sshd -D 2>&1 > /dev/null &
      cd /home/db2inst1/maximo/tools/maximo
      chmod +x TDToolkit.sh
      chmod +x updatedb.sh
      dos2unix TDToolkit.sh
      dos2unix updatedb.sh
      ./updatedb.sh
      export JAVA_HOME=/opt/ibm/java-x86_64-70
      export JRE_HOME=/opt//home/db2inst1/maximoibm/java-x86_64-70/jre
      export PATH=${JAVA_HOME}/bin:$PATH

      cd /
      cd /tmp/localization/Tpae7610
      unzip \*.zip
      cp -a /tmp/localization/Tpae7610/*  /home/db2inst1/maximo/

      cd /tmp/localization/Lightning7604
      unzip \*.zip
      cp -a /tmp/localization/Lightning7604/*  /home/db2inst1/maximo/

      cd /tmp/localization/BOTC7610
      unzip \*.zip
      cp -a /tmp/localization/BOTC7610/* /home/db2inst1/maximo/

      cd /tmp
      #remove localization folder from tmp folder
      rm -rf localization

      cd /home/db2inst1/maximo/tools/maximo
      #./TDToolkit.sh -addlangPT -useexpander
      #./TDToolkit.sh -addlangJA -useexpander
      #./TDToolkit.sh -addlangDE -useexpander
      #./TDToolkit.sh -addlangIT -useexpander
      #./TDToolkit.sh -addlangFR -useexpander
      #./TDToolkit.sh -addlangES -useexpander

      #./TDToolkit.sh -pmpupdatenxtgenui -useexpander 
      # ./TDToolkit.sh -pmpupdatez_botc -useexpander

      chmod -R 777 /home/db2inst1/maximo/tools/maximo/log
      #healthcheck looks for this file to indicate the container is initialized
      touch /tmp/container_started
      while true; do sleep 1000; done
      exec "/bin/bash"
    #statements
  else
    su - db2inst1 <<EOH
    db2start
    db2 catalog db maxdb76 on /db2fs
    db2 terminate
    db2 connect to maxdb76
EOH
    touch /tmp/container_started
    while true; do sleep 1000; done
    exec "/bin/bash"
  fi

  sleep 10
fi

1 个答案:

答案 0 :(得分:0)

目录/ tmp / localization / Tpae7610 /下的文件没有权限。

尝试命令cp -v(详细将显示复制的文件) 在脚本中注释rm -rf localization。然后调试脚本。