0

I created a dockerfile and a docker-compose in order to mount an image with some instructions. The instruction I would like to use is as follows:

raster2pgsql -s 4326 -C -F -I -t 100x100 /data/dem/w*.tif public.italy | PGPASSWORD=password psql -h localhost -p 5432 -U admin -d elevation

By opening the container terminal and typing this instruction, everything proceeds smoothly. What I would like to do, to avoid running all the times is to enter this instruction inside my dockerfile but I couldn't get anything, not even an error message:

RUN raster2pgsql -s 4326 -C -F -I -t 100x100 /data/dem/w*.tif public.italy && PGPASSWORD=password psql -h localhost -p 5432 -U admin -d elevation

my dockerfile:

FROM kartoza/postgis

# LABEL about the custom image
LABEL maintainer="xx.yy@gmail.com"
LABEL version="0.1"
LABEL description="This is a custom Docker Image for elevation data."


RUN apt-get update && apt-get install -y \
  gdal-bin \
  postgis \
  && rm -rf /var/lib/apt/lists/*

COPY ./dem/* /data/dem/

RUN raster2pgsql -s 4326 -C -F -I -t 100x100 /data/dem/w*.tif public.italy | PGPASSWORD=password psql -h localhost -p 5432 -U admin -d elevation

and

version: "3.8"

services:

  postgis:
    build:
      context: .
      dockerfile: ./Dockerfile
    #image: kartoza/postgis:${POSTGIS_VERSION_TAG}
    container_name: postgis
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASS=${POSTGRES_PASS}
      - POSTGRES_DB=${POSTGRES_DB}
      - ALLOW_IP_RANGE=${POSTGRES_ALLOW_IP_RANGE}
      - POSTGRES_MULTIPLE_EXTENSIONS=${POSTGRES_MULTIPLE_EXTENSIONS}
      - POSTGRES_DATA_VOLUME:${POSTGRES_DATA_VOLUME}
    restart: on-failure
    volumes:
      - postgis-data:${POSTGRES_DATA_VOLUME}
    networks:
      - postgis_network

  pgadmin:
    image: dpage/pgadmin4:${PGADIM_VERION_TAG}
    container_name: ${PGADIM_CONTAINER_NAME}
    ports:
      - "5050:80"
    restart: always
    environment:
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
      - PGADMIN_CONFIG_SERVER_MODE:${PGADMIN_CONFIG_SERVER_MODE}
    networks:
      - postgis_network
    volumes:
      - pgadmin-data:${PGADIM_DATA_VOLUME}
        #depends_on:
      #postgis:
      #condition: service_healthy

  cloudbeaver:
    image: dbeaver/cloudbeaver:23.1.0
    container_name: cloudbeaver_container
    restart: always
    ports:
      - "8085:8978"
    volumes:
      - cloudbeaver-data:/opt/cloudbeaver/workspace
    networks:
      - postgis_network


volumes:
  postgis-data:
  pgadmin-data:
  cloudbeaver-data:

networks:
  postgis_network:
      driver: bridge
Gianni Spear
  • 7,033
  • 22
  • 82
  • 131
  • Pretty sure it's just the pipe: https://stackoverflow.com/questions/30441178/how-to-use-pipesioredirection-in-dockerfile-run – Mikael Öhman Jul 03 '23 at 22:25
  • nope sorry. It not works with the line RUN sh -c "raster2pgsql -s 4326 -C -F -I -t 100x100 /data/dem/w*.tif public.italy | PGPASSWORD=password psql -h localhost -p 5432 -U admin -d elevation" – Gianni Spear Jul 03 '23 at 22:31
  • [Starting and populating a Postgres container in Docker](https://stackoverflow.com/questions/29600369/starting-and-populating-a-postgres-container-in-docker) suggests leaving a `*.sql` file in `/docker-entrypoint-initdb.d` in the database container, and then letting the standard database image startup import it for you. Will that approach work for you? (For a couple of technical reasons, you can't `RUN psql` in a Dockerfile.) – David Maze Jul 04 '23 at 00:34

0 Answers0