- Open your linux terminal and run the following
docker-compose up --build
Do not close this terminal
Open another terminal and do the following:
- Get your db container's name using
docker ps
which will give list like the following
![image](https://private-user-images.githubusercontent.com/6050613/337562209-30a7cfa8-e35c-474f-acd4-d0a5f463ecc9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTgwODMsIm5iZiI6MTcyNDMxNzc4MywicGF0aCI6Ii82MDUwNjEzLzMzNzU2MjIwOS0zMGE3Y2ZhOC1lMzVjLTQ3NGYtYWNkNC1kMGE1ZjQ2M2VjYzkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjJUMDkwOTQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTNmZWE4NWU3MDg0YjVkNGY1OGJjYzE4NDdlNGMwZjU2NWRhMTM0NzA5Y2FkNTg2ZWM1ODYxNGQwYzg4YjA0MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.rBXT37Yg-mSZGTRpdQxwppzkvHiCi9aQ2b7hAMCNDo4)
-
Then go inside the container using the command
docker exec -it <container_name> bash
. In my case it wasflask_with_db_docker-postgres-1
as selected in the screenshot above -
Then run the psql shell using
psql -U postgres
command -
Execute the table creation SQL query
CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL );
http://127.0.0.1:5001/users
The response will be empty
Now using postman, try to add users to the table.
![image](https://private-user-images.githubusercontent.com/6050613/337563238-f1a57716-a23d-4017-a933-1996e80c1417.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTgwODMsIm5iZiI6MTcyNDMxNzc4MywicGF0aCI6Ii82MDUwNjEzLzMzNzU2MzIzOC1mMWE1NzcxNi1hMjNkLTQwMTctYTkzMy0xOTk2ZTgwYzE0MTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjJUMDkwOTQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9N2Q5NDRlOTIyYWM5OGNkYjRlYzFmY2M1YWNlZjFiZjNkZGI5YWU4NGU0ZmU2ZDQyZmUyMzc2MjkwY2I0OGUxZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.zvEH1VWzwjN-YXOuWEeSZ1UqUlw0eaOPwHTrEcJV6XY)
Again go back to browser, you will see one record
![image](https://private-user-images.githubusercontent.com/6050613/337563379-5b4c98fa-ad6f-4102-bd6c-30ba5c81a8f6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTgwODMsIm5iZiI6MTcyNDMxNzc4MywicGF0aCI6Ii82MDUwNjEzLzMzNzU2MzM3OS01YjRjOThmYS1hZDZmLTQxMDItYmQ2Yy0zMGJhNWM4MWE4ZjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjJUMDkwOTQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjA5OGU2MTAxMTQ2ZWVlYWNlMTQzMmU3MjZjNTJkYjdiMGNkNDk1ZWJkOGVkMTI1YmEzZmJkZWE1NDE2MDU4MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.7IGDsxG5ox1aJVK6omowyLxSDlc0w4M7GbD6Uxd2FxQ)