12/13/2023 0 Comments Docker postgres create database![]() And at the end data folder with CSV file is copied to the container. As environmental properties basic postgres properties are used. bin/bash psql -U postgres psql -c 'create database tenantfours' Share. The problem is - that database is not created I do not understand why it doesnt crea. Finally, port 6666 is exposed.ĭocker-compose.yml builds the Dockerfile from db folder and make it accessible through 5431 port. I try to up several postgres databases by writing docker-compose file and create database when container is up. Later, all files are executed in alphanumerical order, that's why *.sql files start with digits. 2_copy.sql is responsible for copying data from the CSV to postgres.ĭockerfile uses postgres image and copies all *.sql files to /docker-entrypoint-initdb.d/. RUN chmod a+r /docker-entrypoint-initdb.d/*Īnd 2_copy.sql: COPY table_name FROM '/data/datasource.csv' DELIMITER ',' CSV HEADER ġ_init.sql creates the DB table, it has to have the same column names as in CSV file. In the project folder there is the following docker-compose.yml file: version: '3.3'ĭockerfile contains: FROM postgres:alpineĪDD scripts/1_init.sql /docker-entrypoint-initdb.dĪDD scripts/2_copy.sql /docker-entrypoint-initdb.d If you have a better solution you are welcome and I will give a try. I managed to make it work using custom Dockerfile, here's my solution: Project structure data/ĬSV file is located in data folder inside of the project. Finally I concluded to drop and create db before restore. My question is: how to preload the Postgres container with the CSV data file in docker-compose? When I connect to Docker container, run 'psql command and try to get anime table, I get the following error: Did not find any relation named "anime". The database is created correctly, but it doesn't have the table and data. The CSV file is located in the data folder, on the same level as docker-compose.yml.īut it is not working. With that script: copy anime FROM 'docker/data/AnimeList.csv' DELIMITER ',' CSV HEADER I tried to add another volume to docker-compose:. Then, I would like to fill the Postgres database with data from the CSV file. Arjun Gibson Follow 3 min read Photo by Jan Antonin Kolar on Unsplash So you need to use a PostgreSQL. In volume I defined init.sql, which should set up a table: CREATE TABLE anime ( How to use Docker to easily create a PostgreSQL database and run it. ![]() This configuration starts a Postgres database. init.sql:/docker-entrypoint-initdb.d/init.sql ![]() I have the following docker-compose.yml file: version: '3' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |