简体   繁体   中英

How do I run a command from one Docker container in another?

I've got an application and a database container. I bring them up with Docker Compose. The app container needs to wait until the db container is up and then execute a schema initialization SQL. I need to do it after my wait-for-db script is executed thus it should be executed in the CMD of the app container. The problem is that the db container doesn't contain ssh. How do I run a specific command like

sqlplus system/oracle @schema.sql

from the app container against the db container?

Thank you very much!

UPDATE: maybe, there is a way to execute SQL via HTTP in Oracle 12c?

Your DB container shouldn't need ssh. Your wait-for-it script on the app container can test for availability of the oracle listener port 1521 on the db container before proceeding.

Eg in your docker-compose entry for the app container, assuming that "db" is the name of the db container:

command: "./wait-for-it.sh db:1521 runsql.sh"

where runsql.sh is a script that obtains the necessary oracle environment vars and runs sqlplus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM