I have a Docker image with GDAL installed. In the Dockerfile, the last command is CMD ["python", "script.py"]
. This Python script runs gdalwarp
with subprocess.run()
.
I ran the script in two different ways and each of them gives a different output.
docker run -it <image_name> bash
and then python script.py
, this gives the expected outputgdalinfo
output:
Driver: GTiff/GeoTIFF
Files: file.tif
file.XML
Size is 19771, 19771
Coordinate System is:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (16.295439814814817,48.338634259259265)
Pixel Size = (0.000004629629630,-0.000004629629630)
Metadata:
AREA_OR_POINT=Area
METADATATYPE=DIMAP
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 16.2954398, 48.3386343) ( 16d17'43.58"E, 48d20'19.08"N)
Lower Left ( 16.2954398, 48.2471019) ( 16d17'43.58"E, 48d14'49.57"N)
Upper Right ( 16.3869722, 48.3386343) ( 16d23'13.10"E, 48d20'19.08"N)
Lower Right ( 16.3869722, 48.2471019) ( 16d23'13.10"E, 48d14'49.57"N)
Center ( 16.3412060, 48.2928681) ( 16d20'28.34"E, 48d17'34.32"N)
Band 1 Block=19771x1 Type=UInt16, ColorInterp=Red
Band 2 Block=19771x1 Type=UInt16, ColorInterp=Green
Band 3 Block=19771x1 Type=UInt16, ColorInterp=Blue
Band 4 Block=19771x1 Type=UInt16, ColorInterp=Undefined
CMD
: docker run <image_name>
, which gives a different output, GDAL seems to lose the coordinate system information, as well as its ordergdalinfo
output:
Driver: GTiff/GeoTIFF
Files: file.tif
file.XML
Size is 19771, 19771
Origin = (48.247101851844533,16.386972222229545)
Pixel Size = (0.000004629629630,-0.000004629629630)
Metadata:
METADATATYPE=DIMAP
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 48.2471019, 16.3869722)
Lower Left ( 48.2471019, 16.2954398)
Upper Right ( 48.3386343, 16.3869722)
Lower Right ( 48.3386343, 16.2954398)
Center ( 48.2928681, 16.3412060)
Band 1 Block=19771x1 Type=UInt16, ColorInterp=Red
Band 2 Block=19771x1 Type=UInt16, ColorInterp=Green
Band 3 Block=19771x1 Type=UInt16, ColorInterp=Blue
Band 4 Block=19771x1 Type=UInt16, ColorInterp=Undefined
I am dismayed as the script and the environment is exactly the same in both cases. When I run the script from inside the container, python script.py
is the first and only command I run.
What could cause such a behavior?
EDIT:
I also tried running the container in the following ways, which all give faulty outputs:
docker run <image_name> python script.py
docker run -it <image_name> python script.py
docker run <image_name> bash -c "python script.py"
docker run -it <image_name> bash -c "python script.py"
docker run <image_name>
with CMD ["bash", "-c", "python script.py"]
The issue came from a missing environment variable.
See this answer on ServerFault for details.
The solution for me was to change the ENTRYPOINT in my Dockerfile (notice the -l
option):
ENTRYPOINT ["/bin/bash", "-l", "-c"]