简体   繁体   中英

Docker container calls binary from another container

I have two dockers containers, one with Apache (+ PHP) and another with PostgreSQL (+ PostGIS, a spatial extension for PostgreSQL database).

PostGIS has a binary (shp2pgsql) to transform a shapefile data in SQL instructions. When I need to do this, I run the following command:

/usr/bin/shp2pgsql {...arguments...} filename.shp > insql.sql

In a specific case, when the user uploads a shapefile (in apache+php container), I need to run shp2pgsql in PostgreSQL+PostGIS container.

I have already tried:

  • Expose docker daemon to Apache docker container and call the binary shp2pgsql using docker exec command, but with no success, because apache user (who calls docker exec) don't have permission for it.

  • Share volume "/usr/bin/" from PostgreSQL container to Apache container, but with no success, because the binary (shp2pgsql) have dependencies with others libraries (in others folders).

Is there a elegant (or not) and viable way to do this? Is there others alternatives for this problem?

Any suggestions or ideas are more than welcome.

Not really elegant, definitely not secure, but a solution would be to invoke the shp2pgsql in a different, new postgres container. From the apache container. Something like described in this thread .

Another option is go micro-service-y and create a new image which would be based on the postgres one and contain a simple script or binary that would expose the result of the execution of the shp2pgsql via some (REST?) interface, that would in turn be streamed by apache/php. This assumes you need only the shp2pgsql binary and its dependencies, not the postgres data. Otherwise you could put this custom service into the same container as the original database, even though violating the docker's preference of one process per container.

Third approach could actually be to install the needed binaries onto the apache container.

Again, neither of the solutions is very elegant to me, let's see whether somebody comes with something better.

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