Task 05 - Run the containerized app and add a booking
Introduction
You created a Docker container and pushed the container to ACR in previous tasks. Now, you’ll run the container and view the app in a browser. Since this is the first time you are running the app, you’ll need to run a process to create the database schema and populate the tables with data.
Now, you can view the various pages for the app and try out the features.
Description
In this task, you’ll run the Docker app container and then display the setup page for the app. You’ll create the database schema and populate the tables with data. You’ll review common app pages and add a booking record. Finally, you’ll search for the record you just added to verify that the record was successfully added to the database.
The key steps are as follows:
- Run the Docker container on port 8000.
- Open the app at http://localhost:8000/setup.
- Run the setup process in the app to add records to the database.
- Review the app pages.
-
Add the following booking record:
Field Value Hotel Contoso Suites Athens Visitor Emma Davis Check-in 12/28/2024 Check-out 01/05/2025 Adults 2 Rooms 1 - Verify that the new record is saved and close the browser window.
Success Criteria
- You can view the app in a web browser.
- You can add a booking record to the app and verify that the record is saved and is searchable.
Learning Resources
Manage container images in Azure Container Registry
Solution
Expand this section to view the solution
-
Replace the ENTER_CONNECTION_STRING_FROM_EX02_TASK04 placeholder text in the following command with the connection string you recorded in the previous task. Enter the command at the Visual Studio Code Terminal window prompt and then select Enter. This command starts the containerized app.
docker run -p 8000:8000 -e POSTGRES_CONNECTION_STRING="ENTER_CONNECTION_STRING_FROM_EX02_TASK04;" pycontosohotel:v1.0.0
You may minimize Visual Studio Code but don’t close the Visual Studio Code Terminal window at this time.
-
Open a web browser and go to http://localhost:8000/setup. The Contoso Hotel Setup page displays.
-
On the Contoso Hotel Setup page, select Setup database. This launches a script that creates the database schema and populates the tables with data.
The page updates when the script completes.
-
On the Contoso Hotel Setup page, select Home. The Home page for the app displays.
-
On the Home page, select the calendar icon to go to the Bookings page.
-
On the Bookings page, select New Booking.
-
Enter the following information into the page and then select Add Booking. The page will update to show you that the booking is successfully created.
Field Value Hotel Contoso Suites Athens Visitor Emma Davis Check-in 12/28/2024 Check-out 01/05/2025 Adults 2 Rooms 1 The Visitor field doesn’t search properly. Type in the letter ‘a’ into the field and select a name from the dropdown list.
-
On the Bookings page, select List Bookings.
-
Enter Emma Davis, or whichever Visitor you selected, in the Search field. The booking that you created should appear in the list of bookings.
-
Close the browser window.
-
In Visual Studio Code, select Ctrl+C from the Terminal pane to exit the running worker processes.
-
Leave Visual Studio Code open. You’ll use the tool again in the next exercise.