Objectives
- Build a Docker image
- Use PostgreSQL
Review: Docker Commands
Our Docker Exercises
- What is an image vs a container?
- How do you build an image? Get the specific command and options.
- How do you run a container? Get the specific command and options.
Using Docker to Run PostgreSQL
- Create a directory for this exercise/demo.
- Download the files in postgresql into
your directory. Recall that
Dockerfile
should not have
an extension.
- View the contents of both files. What does the Dockerfile do?
What does clubdata.sql contain?
- Build the image from the
Dockerfile
, naming the image
something like psql
- Run the container and name it something like
psql
.
(Yeah, they can be the same.)
Practicing with PostgreSQL
Connect to the database (within the container)
- Get a command-line interface/shell for the container.
- Run psql exercises
What is exercises referring to?
You should get an error because there is no root user. (If you get a different error, let me know.)
Do you know a user name? What about the password?
- Run
psql -U <username> -W exercises
where
username is the database's username.
- Enter the password. (Full disclosure, you can also access the
database if you don't use the
-W
option for the
password.)
- You're now using PostgreSQL!
Using the database
Let's find out more about the database!
- \d
- \d facilities
These commands do not require ; They are not SQL commands but
ways to get information about the database. These commands are
different in other DBMSs.
- Use the above command and look at the other two tables too.
- How are the tables related? What information can we get from
the tables?
- Where was this information in the
clubdata.sql
file?
Now, let's look at the data!
- Get all the information about the facilities
select * from facilities;
- Get all the information about the members.
- Get all the information about the bookings.
- How do I get the bookings for one specific member?
- How do I get the bookings for one specific member and also see
the information about the member?
- How do I also see what facilities those are in?
- How do I see this information for all members?
Now, let's add some data!
- Add yourself as a customer.
- Add DARC as a new facility.
- Create a new booking for yourself at DARC.