mirror of
https://github.com/Red5d/docker-autocompose
synced 2026-01-18 14:38:02 +00:00
Compare commits
7 Commits
1.1
...
d783902265
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d783902265 | ||
|
|
e6badd31c3 | ||
|
|
3f756235b2 | ||
|
|
b9c096dd94 | ||
|
|
e7dbe41f23 | ||
|
|
d976d520b4 | ||
|
|
ec211717ed |
@@ -43,3 +43,6 @@ Use the new image to generate a docker-compose file from a running container or
|
||||
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose <container-name-or-id> <additional-names-or-ids>...
|
||||
|
||||
To print out all containers in a docker-compose format:
|
||||
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose $(docker ps -aq)
|
||||
|
||||
@@ -10,12 +10,14 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
struct = {}
|
||||
networks = []
|
||||
networks = set()
|
||||
for cname in args.cnames:
|
||||
cfile, networks = generate(cname)
|
||||
struct.update(cfile)
|
||||
cfile, c_networks = generate(cname)
|
||||
|
||||
render(struct, args, networks)
|
||||
struct.update(cfile)
|
||||
networks.update(c_networks)
|
||||
|
||||
render(struct, args, list(networks))
|
||||
|
||||
|
||||
def render(struct, args, networks):
|
||||
@@ -32,7 +34,7 @@ def generate(cname):
|
||||
try:
|
||||
cid = [x.short_id for x in c.containers.list(all=True) if cname == x.name or x.short_id in cname][0]
|
||||
except IndexError:
|
||||
print("That container is not available.")
|
||||
print("That container is not available.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
cattrs = c.containers.get(cid).attrs
|
||||
@@ -94,12 +96,12 @@ def generate(cname):
|
||||
networks[network.attrs['Name']] = {'external': (not network.attrs['Internal'])}
|
||||
|
||||
# Check for command and add it if present.
|
||||
if cattrs['Config']['Cmd'] != None:
|
||||
values['command'] = " ".join(cattrs['Config']['Cmd']),
|
||||
if cattrs['Config']['Cmd'] is not None:
|
||||
values['command'] = cattrs['Config']['Cmd']
|
||||
|
||||
# Check for exposed/bound ports and add them if needed.
|
||||
try:
|
||||
expose_value = list(cattrs['Config']['ExposedPorts'].keys())
|
||||
expose_value = list(cattrs['Config']['ExposedPorts'].keys())
|
||||
ports_value = [cattrs['HostConfig']['PortBindings'][key][0]['HostIp']+':'+cattrs['HostConfig']['PortBindings'][key][0]['HostPort']+':'+key for key in cattrs['HostConfig']['PortBindings']]
|
||||
|
||||
# If bound ports found, don't use the 'expose' value.
|
||||
|
||||
Reference in New Issue
Block a user