![]() But if we check the log of this container $ docker container logs test_preloaded_db Now we have a docker image that has our database loaded. My_db = # SELECT * FROM clients id | nameĪwesome. You are now connected to database “my_db” as user “postgres”. (password is postgres) $ psql -h localhost -U postgres We can see in our database that the database was created. t preloaded_db:latestĪnd start a container with the generated image $ docker container run -d -rm -p 5432:5432 -e POSTGRES_PASSWORD =postgres -e POSTGRES_USER =postgres -name test_preloaded_db preloaded_db:latest If we build this image $ docker image build. FROM postgres:11-alpine COPY test_dump.sql /docker-entrypoint-initdb.d/ The following Dockerfile uses postgres:11-alpine as base image and copies test_dump.sql file to the entrypoint folder. After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service. If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). If we want to start a Postgresql Docker container with this dump loaded to share with our team, we can add this SQL file into the /docker-entrypoint-initdb.d/ folder inside the container, like explained into the Postgresql Image docs from DockerHub. It is a simple database with a Clients table and 2 records. clients ADD CONSTRAINT clients_pkey PRIMARY KEY ( id ) - PostgreSQL database dump complete. setval ( 'public.clients_id_seq', 2, true ) - Name: clients clients_pkey Type: CONSTRAINT Schema: public Owner: postgres - ALTER TABLE ONLY public. Name: clients_id_seq Type: SEQUENCE SET Schema: public Owner: postgres - SELECT pg_catalog. clients ( id, name ) FROM stdin 1 Client 1 2 Client 2 \. clients ALTER COLUMN id SET DEFAULT nextval ( 'public.clients_id_seq' :: regclass ) - Data for Name: clients Type: TABLE DATA Schema: public Owner: postgres - COPY public. ![]() id - Name: clients id Type: DEFAULT Schema: public Owner: postgres - ALTER TABLE ONLY public. clients_id_seq OWNER TO postgres - Name: clients_id_seq Type: SEQUENCE OWNED BY Schema: public Owner: postgres - ALTER SEQUENCE public. clients_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1 ALTER TABLE public. clients OWNER TO postgres - Name: clients_id_seq Type: SEQUENCE Schema: public Owner: postgres - CREATE SEQUENCE public. clients ( id integer NOT NULL, name character varying ( 150 ) NOT NULL ) ALTER TABLE public. set_config ( 'search_path', '', false ) SET check_function_bodies = false SET xmloption = content SET client_min_messages = warning SET row_security = off SET default_tablespace = '' SET default_with_oids = false - Name: clients Type: TABLE Schema: public Owner: postgres - CREATE TABLE public. set_config ( 'search_path', '', false ) SET check_function_bodies = false SET xmloption = content SET client_min_messages = warning SET row_security = off - Name: my_db Type: DATABASE Schema: - Owner: postgres - CREATE DATABASE my_db WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' ALTER DATABASE my_db OWNER TO postgres \ connect my_db SET statement_timeout = 0 SET lock_timeout = 0 SET idle_in_transaction_session_timeout = 0 SET client_encoding = 'UTF8' SET standard_conforming_strings = on SELECT pg_catalog. I tried out the dump by installing MySQL on my host, it can be restored.Imagine that we have the following Postgresql database dump: - PostgreSQL database dump - Dumped from database version 11.5 - Dumped by pg_dump version 11.3 SET statement_timeout = 0 SET lock_timeout = 0 SET idle_in_transaction_session_timeout = 0 SET client_encoding = 'UTF8' SET standard_conforming_strings = on SELECT pg_catalog. It seems that it does nothing, because the terminal responds too quickly. # -password=test_pass DATABASE SHOW TABLES # To restore a dump `docker exec -i my_mysql /usr/bin/mysql -u root # To open up console, run `docker exec -it my_mysql bash`. # WORKS ONLY IN USER'S DIR ON WINDOWS (~/Downloads for example) # The current directory will be mounted to '/var/www/html' # (192.168.99.100 for example - shown on the top of the console) # 'localhost' does not works from the host, but the IP of docker itself # Use Dockerfile in this dir to build the image I'm sure this is a duplicated topic, but I simply cannot get it done: I like to restore my database dump to MySQL container in run time, without modifying the docker-compose.yml file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |