使用oracle在docker中迁移运行的flyway

时间:2018-09-13 10:29:14

标签: oracle docker docker-compose dockerfile flyway

我有一个运行安装脚本的docker文件。它找不到用于运行迁移的oracle连接。在我的安装脚本中,我将导出设置为oracle home和tns目录

结构

bin
conf
docker-compose-ccpdev1.yml
Dockerfile
HOSTNAMES.md
include
INSTALL.md
install.sh
README.md
sql

我的 Dockerfile 包含以下内容

# environment
ENV ORACLE_HOME="/opt/SP/instantclient_12_2"
ENV TNS_ADMIN="$ORACLE_HOME/network/admin"
ENV LD_LIBRARY_PATH="$ORACLE_HOME"
ENV PATH="$ORACLE_HOME:$TNS_ADMIN:/opt/SP/ccp-ops/bin:/opt/rh/rh-php71/root/bin:/opt/rh/rh-php71/root/sbin:/opt/rh/rh-nodejs8/root/usr/bin:$PATH"
ENV PHP_HOME="/opt/rh/rh-php71/root"
ENV https_proxy="proxy01.domain-is.de:8080"

# install
RUN yum update -y; yum install -y rh-php71 rh-php71-php-xml rh-php71-php-json rh-php71-php-ldap rh-php71-php-fpm rh-php71-php-devel rh-php71-php-opcache rh-nodejs8 libaio java wget; yum groupinstall 'Development Tools' -y; yum clean all; /root/install.sh;

VOLUME [ "/sys/fs/cgroup" ]

# run
CMD ["/usr/sbin/init"]

# ports
EXPOSE 80
EXPOSE 443
EXPOSE 8080
EXPOSE 3000

我的 install.sh 文件包含

export ORACLE_HOME=/opt/SP/instantclient_12_2
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$PATH:$ORACLE_HOME:$TNS_ADMIN
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
export https_proxy=proxy01.domain-is.de:8080

mv /opt/SP/flyway-commandline-5.1.4.tar.gz/flyway-5.1.4 /opt/SP
rm -rf /opt/SP/flyway-commandline-5.1.4.tar.gz
mv /root/flyway.conf /opt/SP/flyway-5.1.4/conf
cp /opt/SP/instantclient_12_2/ojdbc8.jar /opt/SP/flyway-5.1.4/jars/
cd /opt/SP/flyway-5.1.4
./flyway baseline
cp /root/create_ccp_schemas.sql sql/V2__create_ccp_schemas.sql
./flyway migrate
sed -i 's/flyway\.user\=sys as sysdba/flyway\.user\=c##CCP/' conf/flyway.conf
sed -i 's/flyway\.password\=Oradoc_db1/flyway\.password\=CCP/' conf/flyway.conf
./flyway baseline -baselineVersion=2
cp /root/import_schema.sql sql/V3__import_schema.sql
sed -i 's/CCPRW/C##CCPRW/' sql/V3__import_schema.sql
sed -i 's/CCPRO/C##CCPRO/' sql/V3__import_schema.sql
./flyway migrate
cp /root/import_data.sql sql/V4__import_data.sql
sed -i 's/CCPRW/C##CCPRW/' sql/V4__import_data.sql
sed -i 's/CCPRO/C##CCPRO/' sql/V4__import_data.sql
sed -i '/REM INSERTING into/d' sql/V4__import_data.sql
sed -i '/SET DEFINE OFF/d' sql/V4__import_data.sql

我得到的错误是

WARNING: Connection error: IO Error: could not resolve the connect identifier  "ccp.oracle:1521/ORCLCDB.localdomain" (caused by could not resolve the connect identifier  "ccp.oracle:1521/ORCLCDB.localdomain") Retrying in 1 sec...
...
ERROR:
Unable to obtain connection from database (jdbc:oracle:thin:@ccp.oracle:1521/ORCLCDB.localdomain) for user 'sys as sysdba': IO Error: could not resolve the connect identifier  "ccp.oracle:1521/ORCLCDB.localdomain"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : 08006
Error Code : 17002
Message    : IO Error: could not resolve the connect identifier  "ccp.oracle:1521/ORCLCDB.localdomain"

我使用setenforce 0; docker build -t ccp-apache-php-fpm .

构建图像

如果我登录到docker映像并手动运行flyway,它将起作用。我使用

登录图像
docker-compose -p ccpdev1 -f /root/ccp-apache-php-fpm/docker-compose-ccpdev1.yml up -d --remove-orphans
docker container exec -it ccp_app_1 /bin/bash

更新

我已将飞行通道设置移至docker composer文件中的安装后位置。我现在遇到的问题是它连续运行并且容器不断重启

文件文件

version: '3'

services:
  ccp.oracle:
    container_name: ccp_oracle_1
    hostname: ccp_oracle1
    image: registry-beta.cdaas.domain.com/oracle/database/enterprise:12.2.0.1
    restart: unless-stopped
    ports:
      - "33001:1521"
    networks:
      - backend1
  ccp.app:
    container_name: ccp_app_1
    hostname: ccp_app1
    image: ccp-apache-php-fpm
    restart: unless-stopped
    ports:
      - "33080:80"
      - "33000:3000"
    links:
      - ccp.oracle
    command: ["./root/wait_for_oracle.sh"]
    networks:
      - backend1
  ccp.worker:
    container_name: ccp_worker_1
    hostname: ccp_worker1
    image: ccp-apache-php-fpm
    restart: unless-stopped
    links:
      - ccp.app
      - ccp.oracle
    networks:
      - backend1
  ccp.jenkins:
    container_name: ccp_jenkins_1
    hostname: ccp_jenkins1
    image: jenkins
    restart: unless-stopped
    ports:
      - "33081:8080"
      - "50001:50000"
    networks:
      - backend1
networks:
  backend1:
    driver: "bridge"

0 个答案:

没有答案