P
P
p-oleg2020-08-25 12:04:04
Docker
p-oleg, 2020-08-25 12:04:04

Why is Docker Postgres ignoring the base seeding script?

My docker-compose.yml (Windows 10)

version: '3'

services:
  db:
    image: postgres:9.5.23
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=my_db
      - POSTGRES_USER=my_user
      - POSTGRES_PASSWORD=my_password
    volumes:
      - postgres-data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
  postgres-data:


$docker-compose upswears at this line:
./init.sql:/docker-entrypoint-initdb.d/init.sql

db_1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
db_1  | psql:/docker-entrypoint-initdb.d/init.sql:0: could not read from input file: Is a directory


I start from the current directory, the init.sql file is present.
For some reason, it says that this is not a file, but a directory.
Without this line, everything works and the database is created, but of course empty.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
p-oleg, 2020-08-25
@p-oleg

Solved the problem via Dockerfile :

FROM postgres:9.5.23
ADD ./sqls/init.sql /docker-entrypoint-initdb.d/

And docker-compose.yml is now:
version: '3'

services:
  db:
    build: .
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=my_db
      - POSTGRES_USER=my_user
      - POSTGRES_PASSWORD=my_password
    volumes:
      - postgres-data:/var/lib/postgresql/data
volumes:
  postgres-data:

Everything started up and worked.

V
Vitaly Karasik, 2020-08-25
@vitaly_il1

1) what is init.sql really the file you already checked?
2) try mapping like this:
- copy init.sql to the sqls directory
- sqls:/docker-entrypoint-initdb.d

E
EmachinesDIMA, 2021-10-26
@EmachinesDIMA

features of declaring volumes (volumes) in docker:
----------------------------------------- -----------------------------------------------------
a
) `` .gitlab-ci.yml
job_name:
script:
- mkdir -p __workdir__
artifacts:
paths:
- __workdir__/
expire_in: 1h
when: on_success
``` Things
to note:
1. first create a working directory!!! With the "-p" tag, it will create recursively where necessary. The simple "mkdir" command only works in a local folder.
2. Artifacts. Add "/" to the end of the path.
-------------------------------------------------- --------------------------------------------
b)
``` docker-compose.yml
---
version: '3.7'
services:
app_name:
build:
dockerfile: Dockerfile
context: ../../
volumes:
- "upload_react_volumes:__workdir__:rw"
# - __workdir__:/home/ node
volumes:
upload_react_volumes: {}
``` What I'm
paying attention to:
1. The build is from a Dockerfile
2. Write "__path_to_folder_on_host__:__path_in_container_" - will not work, so
3. so declare the volume name in a separate `volumes` block, but in the structure app_name in volumes declare it by specifying the path to the working folder on the host and access rights.
-------------------------------------------------- -----------------------------------------------------
c) - ambiguous. May be redundant and misleading. But let it be, maybe it will come in handy.
``` Dockerfile
FROM image:latest
ADD __workdir__/ /home/node/
``` Things to watch
out for:
1. Define this directory in your Dockerfile.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question