4

I am learning to use docker. I am setting up a database using postgresql and pgadmin4 using docker. I wrote a docker-compose.yml file as follows,

version: '3.8'
services:
  db:
    container_name: postgres
    image: postgres
    restart: always
    volumes: 
      - ${HOME}/Desktop/dbms-2/:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: root
      POSTGRES_DB: test_db
    ports:
      - "5432:5432"
    build:
      context: .
      dockerfile: Dockerfile 
  pgadmin:
    container_name: pgadmin4
    image: dpage/pgadmin4
    restart: always
    volumes: 
      - ${HOME}/Desktop/dbms-2/:/var/lib/pgadmin4/storage
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - "5050:80"

And a docker file to initiate SQL scripts in Postgres as follows, (I have docker-entrypoint-initdb.d sub directory and docker-compose.yml in the same root directory.)

FROM postgres:latest
COPY docker-entrypoint-initdb.d/*.sql /docker-entrypoint-initdb.d/
RUN chmod a+r /docker-entrypoint-initdb.d/*
EXPOSE 6666

Now I have my csv files containing tables in another directory in local file system. when I tried to import them from pgAdmin4 GUI after copying those files into /var/lib/pgadmin/storage/admin_admin.com/ and ${HOME}/Desktop/dbms-2/ directories, I was getting an

[Errno 13] Permission denied: '/var/lib/pgadmin/storage/admin_admin.com/name.basics.tsv'.

Is there any better way of importing tables than these? And what is the mistake I have made here? And How can I merge this docker-compose.yml and Dockerfile into only one docker-compose.yml file.

Akash Tadwai
  • 100
  • 1
  • 9

2 Answers2

0

You can upload files from the PgAdmin GUI.

Here is a good article about how to do it.

enter image description here

Eliaz Bobadilla
  • 479
  • 4
  • 16
0

I could not figure out how to make files available to the docker container. This solution works though. You don't need to use pgadmin.

docker exec -i postgrescontaineer psql -U postgres mydatabase < /home/user/db.sql

pwaterz
  • 658
  • 5
  • 11