使用Docker-compose设置Oracle数据库

j2qf4p5b  于 2023-01-01  发布在  Docker
关注(0)|答案(2)|浏览(330)

我想用Oracle XE启动一个Docker容器,然后运行一个SQL脚本(setup_database. sql),在Docker组合中创建一些表。
如何将以下命令集成到我的docker-compose中:

docker run -d -p 49161:1521 -v "$PWD":/duo --name duodb --hostname duodb --network duo-test -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g-r2

在容器中运行终端:

docker exec -ti duodb /bin/bash

进入正确的目录:

cd duo/sql

启动setup_database脚本:

sqlplus system/oracle@xe @setup_database

我试着运行这个:

oracle:
    container_name: duodb
    image: wnameless/oracle-xe-11g-r2 
    ports:
        - '49161:1521'
    volumes:
        - .:/duo
    command: ["/bin/bash", "-c", "sqlplus system/oracle@xe @setup_database"]
    environment:
        - ORACLE_ALLOW_REMOTE=true

但这会输出以下错误:

Creating network "duo_default" with the default driver
Creating duodb
Creating duomail
Creating duolocal
Attaching to duomail, duodb, duolocal
duomail      | MailDev webapp running at http://0.0.0.0:80
duomail      | MailDev SMTP Server running at 0.0.0.0:25
duodb        | /bin/bash: sqlplus: command not found
duodb exited with code 127
duolocal     | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
duolocal     | [Fri Nov 15 08:17:55.944907 2019] [ssl:warn] [pid 1] AH01909: 172.20.0.3:443:0 server certificate does NOT include an ID which matches the server name
duolocal     | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
duolocal     | [Fri Nov 15 08:17:55.977329 2019] [ssl:warn] [pid 1] AH01909: 172.20.0.3:443:0 server certificate does NOT include an ID which matches the server name
duolocal     | [Fri Nov 15 08:17:55.980390 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.1.32 OpenSSL/1.1.1d configured -- resuming normal operations
duolocal     | [Fri Nov 15 08:17:55.980423 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
rxztt3cl

rxztt3cl1#

我不是DockerMaven,但据我所知,网络是自动创建的,所有容器都在一个Docker-compose文件中,因此你不需要网络。此外,你可以命名服务,所以我认为container-name也是不需要的。你在哪个版本中启动compose文件?你可以尝试类似这样的操作

version: "3"

services:
     duodb:
         image: wnameless/oracle-xe-11g-r2 
         ports:
             - 49161:1521
         volumes:
             - .:/duo
         environment:
             ORACLE_ALLOW_REMOTE=true
             MYSQL_ROOT_USER: root
             MYSQL_ROOT_PASSWORD: secret
             MYSQL_DATABASE: my_database_name
lmvvr0a8

lmvvr0a82#

version: "3"

services:
  duodb:
    image: wnameless/oracle-xe-11g-r2
    ports:
      - 49161:1521
    volumes:
      - .:/duo
    environment:
      - ORACLE_ALLOW_REMOTE=true
      - MYSQL_ROOT_USER=root
      - MYSQL_ROOT_PASSWORD=secret
      - MYSQL_DATABASE=my_database_name

相关问题