|
| 1 | +# 🛠️ Adding dev tools |
| 2 | + |
| 3 | +Before we talk about building and packaging our application as a container image, we want to show one additional capability of using containers for development - **the ease of adding additional tools.** |
| 4 | + |
| 5 | +As we were working in the previous section, we had to use the `psql` command quite a bit. But, not everyone is familiar with `psql`. |
| 6 | + |
| 7 | +What if we could add a web-based tool to make it easier to navigate and work with our database? |
| 8 | + |
| 9 | +Fortunately, there is an open-source tool called [pgAdmin](https://www.pgadmin.org/) that ships a container image! Sweet! |
| 10 | + |
| 11 | + |
| 12 | +## Adding pgAdmin to our stack |
| 13 | + |
| 14 | +Since pgAdmin is already a containerized application, we can simply add it to our `compose.yaml`. |
| 15 | + |
| 16 | +1. In the `compose.yaml` file, add the following configuration: |
| 17 | + |
| 18 | + ```yaml |
| 19 | + services: |
| 20 | + pgadmin: |
| 21 | + image: dpage/pgadmin4:9.6.0 |
| 22 | + ports: |
| 23 | + - 5050:80 |
| 24 | + environment: |
| 25 | + PGADMIN_DEFAULT_EMAIL: [email protected] |
| 26 | + PGADMIN_DEFAULT_PASSWORD: secret |
| 27 | + PGADMIN_CONFIG_SERVER_MODE: 'False' |
| 28 | + PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False' |
| 29 | + depends_on: |
| 30 | + - db |
| 31 | + ``` |
| 32 | +
|
| 33 | + **NOTE:** If you copy the snippet above, remove the first `services` field. |
| 34 | + |
| 35 | + Looking at the `compose.yaml` file, you should now have a single `services` field with two defined services - `db` and `pgadmin`. |
| 36 | + |
| 37 | +2. Use `docker compose` to update the running stack: |
| 38 | + |
| 39 | + ```bash |
| 40 | + docker compose up -d |
| 41 | + ``` |
| 42 | + |
| 43 | + Note that we did NOT have to tear down the existing stack. Compose is smart enough to figure out what changes were made and automatically apply them. |
| 44 | + |
| 45 | +3. Open your browser to http://localhost:5050. Note that it may take a moment for the app to startup. If you need to, you can check the logs by using `docker compose logs`: |
| 46 | + |
| 47 | + ```bash |
| 48 | + docker compose logs pgadmin |
| 49 | + ``` |
| 50 | + |
| 51 | +4. In the middle of the screen in the **Quick Links** section, click on the **Add New Server** link. |
| 52 | + |
| 53 | +5. In the _General_ tab, enter a name of "Development". |
| 54 | + |
| 55 | +6. In the _Connection_ tab, enter the following config: |
| 56 | + |
| 57 | + - **Host name/address**: db |
| 58 | + - **Password**: secret |
| 59 | + - **Save password?** Enable the toggle |
| 60 | + |
| 61 | +7. Click the **Save** button. |
| 62 | + |
| 63 | +8. To view the table content, use the left side nav (named **Object Explorer**) to navigate to **Servers** -> **Development** -> **Databases** -> **postgres** -> **Schemas** -> **public** -> **Tables** -> **memes**. |
| 64 | + |
| 65 | +9. Right-click on the _memes_ table and select **View/Edit Data** -> **All Rows**. |
| 66 | + |
| 67 | +If you'd like feel free to make any changes to the database you'd like! |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +### Auto-configuring pgAdmin |
| 72 | + |
| 73 | +You may be thinking "Wow! This is cool, but I still had to do a few things to set everything up." And you're not wrong! It would be great to provide a seamless experience to our developers. |
| 74 | + |
| 75 | +Many apps provide the ability to provide this configuration at startup, pgAdmin included. That configuration requires a few files to be defined, which go beyond the scope of this training. But, we can define them in our code base and mount them into the pgAdmin container, just as we did for the database containers. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +## 🐳 Docker Recap |
| 80 | + |
| 81 | +Before moving on, let's take a step back and focus on what we learned. |
| 82 | + |
| 83 | +- 🎉 **No install required.** Just as with the database, we can add other containerized services without spending time on setup and configuration. |
| 84 | +- 🎉 **More than just our app's needs.** While it's great to have our app's dependencies in the project, that's not the only thing that can be in our dev environments. |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +## Next steps |
| 89 | + |
| 90 | +Now that we've learned how to use containers to help setup our development environment and add additional tools, let's explore how containers can be used to help ensure our apps work as expected! |
0 commit comments