Support docker exec command
Problem
I've just learned about the new docker exec command. Wouldn't it be great to add it to fig ? I think it really makes sense with fig, as you could run `fig up` and then exec some commands (like a shell) to debug your running containers if something happen. Of course this is already possible by running `docker exec -it your_container cmd`, but I think that it wouldn't hurt to have `fig exec service cmd`. I'll try to give it a shot and submit a PR.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement Docker Exec Support in Fig
The current implementation of Fig does not support the 'docker exec' command, which limits users' ability to interactively debug running containers. This is due to the design of Fig, which primarily focuses on managing container lifecycles rather than providing an interface for executing commands within those containers.
Awaiting Verification
Be the first to verify this fix
- 1
Add Exec Command to Fig
Modify the Fig command parser to recognize 'exec' as a valid command. This will involve updating the command routing logic to handle 'fig exec <service> <command>'.
pythonif command == 'exec': service = args[0] command_to_run = ' '.join(args[1:]) execute_docker_exec(service, command_to_run) - 2
Implement Docker Exec Functionality
Create a function that constructs and executes the appropriate 'docker exec' command based on the service and command provided by the user. Ensure to handle interactive terminal options.
pythondef execute_docker_exec(service, command): os.system(f'docker exec -it {service} {command}') - 3
Update Documentation
Revise the Fig documentation to include the new 'exec' command, providing examples and usage instructions to help users understand how to utilize this feature effectively.
- 4
Test the Implementation
Run a series of tests to ensure that the 'fig exec' command works as expected. This should include executing various commands within different services and verifying the output.
bashfig exec my_service /bin/bash
Validation
To confirm the fix worked, run 'fig up' to start your services, then execute 'fig exec <service> <command>' and verify that the command runs successfully within the specified container. Check for expected output and behavior.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep