Streamlining Docker Compose with Amazon Q Developer
Note: This content was originally published on the AWS Blog and is reproduced here for archival purposes. Please visit the original post for the most up-to-date version.
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with creating and editing Docker Compose files.
A Holiday Home Automation Update
The holiday season often presents an opportunity for some tech tinkering around the house. This year, I decided to upgrade an old Raspberry Pi that manages various home automation tasks to the new Raspberry Pi 5. One of the key components running on this Pi is a Home Assistant container, which I set up a few years ago.
As I began the upgrade process, I realized I had forgotten many of the configuration details. Thankfully, Amazon Q Developer proved to be an invaluable tool in refreshing my memory and optimizing my setup.
Decoding Docker Compose with Q Developer
I started by examining my current Home Assistant configuration. I was particularly curious about the purpose of the
localtime
and dbus
volumes. What did those do again? Instead of sifting through documentation, I simply highlighted these lines, right-clicked, and selected "Amazon Q > Explain".
Q Developer promptly provided a clear explanation:

This concise explanation saved me significant time and effort in understanding my configuration.
Modernizing the Configuration
To bring my setup up to date, I highlighted the entire file and used "Amazon Q > Fix". Q Developer suggested several improvements:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
version: '3.8' # Specify compose file version for better compatibility
services:
homeassistant:
image: homeassistant/home-assistant:latest # Specify image version explicitly
container_name: homeassistant
restart: unless-stopped # Better than 'always' - won't restart if manually stopped
security_opt: # Add security options
- no-new-privileges:true
network_mode: host # Modern syntax instead of deprecated 'net'
environment:
- TZ=${TZ:-UTC} # Set timezone through environment variable
volumes:
- ./config:/config:rw # Explicit read-write permission, using relative path
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
healthcheck: # Add healthcheck
test: ["CMD", "curl", "-f", "http://localhost:8123"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
volumes:
config: # Properly define the volume
name: homeassistant_config
Notice that Amazon Q Developer made several key improvements:
- Updated to version 3.8 of the Compose file format
- Changed deprecated keywords and options
- Added a healthcheck (correctly identifying the Home Assistant port)
- Improved security settings
- Enhanced volume configurations
Adding New Hardware
As a final step, I wanted to add a USB Zigbee dongle to control some sensors and switches. When I started typing the
devices
section, Q Developer suggested adding the USB device:
This suggestion was spot-on, saving me the trouble of looking up the correct syntax for device mapping.
Note: While, Amazon Q supports inline suggestions in YAML, VS Code detects this file as a language called “dockercompose” that Q developer does not support. Therefore, I had to change the language to “YAML” as see in the bottom right corner of the prior screenshot.
Conclusion
Amazon Q Developer has significantly streamlined my Docker Compose workflow. It provided instant explanations for unfamiliar configurations, suggested modern best practices, and even anticipated my hardware additions. This tool has not only saved me time but also ensured that my Home Assistant setup is running with an optimized and secure configuration.
As we continue to explore the capabilities of Amazon Q Developer, it's clear that it's becoming an indispensable tool for developers, whether working on personal projects or professional tasks. Stay tuned for more Q-Bits, where we'll continue to showcase how Amazon Q Developer is revolutionizing our development processes.