Giter Site home page Giter Site logo

docker-autocompose's People

Contributors

acdoussan avatar akshaysalunke13 avatar alpex8 avatar bitals avatar demon avatar docwhat avatar doob187 avatar fmotrifork avatar galaxy102 avatar hgghyxo avatar lunaticmuch avatar moschlar avatar ostafen avatar pr0dt0s avatar red5d avatar rootrider avatar smokes2345 avatar yeyeto2788 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-autocompose's Issues

Operation not permitted

Hi

I'm trying to make / get a yml output for my container but im receiving the Operation not permitted error.

I'm using the docker container method, simply followed the instructions you wrote, pull the image and run the docker command and add the container id / name.

But im seeing the below? Any ideas?

BTW im still learing so bare with me.

Traceback (most recent call last):
File "/usr/src/app/./autocompose.py", line 3, in
import sys, argparse, pyaml, docker
File "/usr/local/lib/python3.10/site-packages/docker-5.0.3-py3.10.egg/docker/init.py", line 2, in
from .api import APIClient
File "/usr/local/lib/python3.10/site-packages/docker-5.0.3-py3.10.egg/docker/api/init.py", line 2, in
from .client import APIClient
File "/usr/local/lib/python3.10/site-packages/docker-5.0.3-py3.10.egg/docker/api/client.py", line 6, in
import requests
File "/usr/local/lib/python3.10/site-packages/requests-2.28.1-py3.10.egg/requests/init.py", line 43, in
import urllib3
File "/usr/local/lib/python3.10/site-packages/urllib3-1.26.9-py3.10.egg/urllib3/init.py", line 7, in
import logging
File "/usr/local/lib/python3.10/logging/init.py", line 57, in
_startTime = time.time()
PermissionError: [Errno 1] Operation not permitted

Volumes null - 'NoneType' object is not iterable

Leveraging the docker approach from https://gist.github.com/marcelrv/e7dac93863945dccc46f70915c84b5db
for c in $CIDS; do mkdir ~/dockercontainers/$c ; docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose $c > ~/dockercontainers/$c/docker-compose.yml ; done
leads to some errors on ubuntu 20.4/latest for some containers as per the error message:

Traceback (most recent call last):
File "/usr/src/app/./autocompose.py", line 164, in
main()
File "/usr/src/app/./autocompose.py", line 27, in main
cfile, c_networks, c_volumes = generate(cname)
File "/usr/src/app/./autocompose.py", line 127, in generate
for volume in values['volumes']:

It seems to relate to no volume defined as per:
docker inspect dcc398077dd8

"Volumes": null,

Outputs Nodes that aren't compatible with v3.

Docker-autocompose (pulled today from git) creates version 3 compose files, but the output isn't exactly compatible with v3.

In the 2.x to 3.x migration documentation , we can see the following note:

Changed in compose-file version 3
The resources section replaces the older resource constraint options in Compose files prior to version 3 (cpu_shares, cpu_quota, cpuset, mem_limit, memswap_limit, mem_swappiness). Refer to Upgrading version 2.x to 3.x to learn about differences between version 2 and 3 of the compose-file format.

Autocompose currently outputs cpu_shares, cpuset, mem_limit, and memswap_limit which aren't valid in v3. The documentation link above shows a sample where you can reserve minimum CPU/Memory and a maximum limit - with CPU being allocated on a percentage basis, and memory on an absolute basis. The provided sample:

    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M

There's no longer any direct control over swap or CPU affinity because apparently compose v3 is designed for Docker's swarm mode and they won't allow any options in there that would provide direct hardware dependencies that might affect how things are assigned in the swarm (like pinning to a CPU when a particular host may not even have that many CPUs/cores).

Version 2.2 introduced the cpus setting, which exists in version 3, though moved to the deploy section. That might provide a good baseline for CPU utilization percentage.

Along with that, we should probably not output mem_limit or memswap_limit anyway when they're set to default values (e.g. memswap_limit: -1). Those are being output from containers without any explicit limit set.

The Networks output also seems invalid, but I haven't had time to dig into the why of that. At first glance, I'd say it's related to this issue comment. There's a good chance that if the network assigned is a bridge network ("Driver": "bridge") with the "com.docker.network.bridge.default_bridge": "true" option, we should just omit the network settings, as they'll be connected to the default bridge by default. I'll probably revisit that in another issue.

Support arm platforms?

I support a variety of software which has a variety of Docker containers and your generator for running containers -> compose is absolutely invaluable in doing that, it makes support so easy having a common language to compare in and for surfacing all the tiny, hidden little things.

But it doesn't work on arm!

Would it be possible to support the various arm platforms? :)

compose.yaml seems to have to many lines

Hello, I have discovered docker-autocompose. It would very helpful!
Which makes me wonder. when I use it to query a container, also like this:
"docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose wikijs >docker-compose.yaml
WARNING: IPv4 forwarding is disabled. Networking will not work."
so far so good.

the compose.yaml is written, then when i test it with docker-compose config i get "docker-compose config.
ERROR: Invalid interpolation format for "environment" option in service "wikijs": "PS1=$(whoami)@$(hostname):$(pwd)$ ""
Error messages, even if I delete the PS1 entry,
there is an error:"
docker-compose config

Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in .
load_entry_point('docker-compose==1.25.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 72, in main
command()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 122, in perform_command
handler(command, command_options)
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 358, in config
compose_config = get_config_from_options('.', self.toplevel_options, additional_options)
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 91, in get_config_from_options
return config.load(
... many more entries

The generated compose.yaml looks good at the beginning.
When I remove the bunch of **label: Entries**, the config check is ok.
So my question is **about label:** why is it, can one disable this? 
**if I delete all entries for label: then there is no further error, so I use it as workaroud** 
===
I'm running a "Debian GNU/Linux 11 (bullseye)"
Docker -v: Docker version 20.10.5+dfsg1,build 55c4c88

PermissionError: [Errno 1] Operation not permitted

Hello,

I am trying to use your script to compose an existing ocntainer, but I get the following error :
pi@raspberrypi:~ $ sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose 4b3cc393a269
Fatal Python error: init_interp_main: can't initialize time
Python runtime state: core initialized
PermissionError: [Errno 1] Operation not permitted

Current thread 0xb6f4e390 (most recent call first):

do you have any idea what could be the issue here ?

Not working anymore?

ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.nginx.networks.bridge contains null, which is an invalid type, it should be an array
services.portainer.networks.bridge contains null, which is an invalid type, it should be an array
services.grafana.labels.com.docker.compose.oneoff contains false, which is an invalid type, it should be a string, number,
or a null
services.influxdb.labels.com.docker.compose.oneoff contains false, which is an invalid type, it should be a string, number,
  nginx:
    networks:
      bridge:
        aliases:

Docker version 18.09.7, build 2d0083d

docker-compose file version

This is a very useful tool.

Are there any plans to provide an option for the Compose File version ?

They have more versions now:

ModuleNotFoundError

Did exactly as instuction says, Ubuntu 20

/autocmp/docker-autocompose# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose Test
Traceback (most recent call last):
  File "/usr/src/app/./autocompose.py", line 3, in <module>
    import sys, argparse, pyaml, docker
  File "/usr/local/lib/python3.9/site-packages/docker-5.0.0-py3.9.egg/docker/__init__.py", line 2, in <module>
    from .api import APIClient
  File "/usr/local/lib/python3.9/site-packages/docker-5.0.0-py3.9.egg/docker/api/__init__.py", line 2, in <module>
    from .client import APIClient
  File "/usr/local/lib/python3.9/site-packages/docker-5.0.0-py3.9.egg/docker/api/client.py", line 10, in <module>
    from .. import auth
  File "/usr/local/lib/python3.9/site-packages/docker-5.0.0-py3.9.egg/docker/auth.py", line 5, in <module>
    import six
ModuleNotFoundError: No module named 'six'

Boolean value should be true/false ?

Get an error like "failed to deploy a stack: must be a boolean or mapping "

In this case an network was made "external: yes", which should be "external:true", the latter works OK

Odroid N2+, Linux 5.15.0-odroid-arm64, Portainer CE 2.18.3,

unexpected keyword argument 'chunked'

Hi,
I installed through pipx, i get this error when running with and without sudo

sudo /home/nial/.local/bin/autocompose jenkins
Traceback (most recent call last):
  File "/home/nial/.local/bin/autocompose", line 8, in <module>
    sys.exit(main())
  File "/home/nial/.local/pipx/venvs/docker-autocompose/bin/autocompose.py", line 11, in main
    generate(args)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/bin/autocompose.py", line 18, in generate
    cid = [x['Id'] for x in c.containers() if args.cname in x['Names'][0]][0]
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/docker/api/container.py", line 85, in containers
    res = self._result(self._get(u, params=params), True)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/docker/utils/decorators.py", line 47, in inner
    return f(self, *args, **kwargs)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/docker/client.py", line 139, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/home/nial/.local/pipx/venvs/docker-autocompose/lib/python3.10/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
TypeError: HTTPConnection.request() got an unexpected keyword argument 'chunked'

Best way to send output to a file?

Just been tinkering with this, obv can't just append tee or > to the end of the docker command and something like |& > output.txt does not work.

What is the best option here?

Dependency versions?

So I've been trying to get this working. I think you need to supply your dependency versions? You could try doing a pip list or pip freeze? I'm planning to give you a pull request with a requirements file so that you can just install dependencies with 1 command (and other people won't run into this problem).

Missing values

It does not export the SHM value:

shm_size: 512MB

Nor the stop timeout value:

stop_grace_period: 2m

Nor the static IP address:

networks:
      example:
        ipv4_address: 172.18.0.2

If these three values could be added that would be really nice.

Cant retrive compose file

Hello,

for some reason this command docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose <CONTAINER NAME> doesnt work for me and returns this error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/api/client.py", line 214, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
                        ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/api/client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests-2.30.0-py3.11.egg/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests-2.30.0-py3.11.egg/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests-2.30.0-py3.11.egg/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests-2.30.0-py3.11.egg/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3-2.0.2-py3.11.egg/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3-2.0.2-py3.11.egg/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
TypeError: HTTPConnection.request() got an unexpected keyword argument 'chunked'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/app/./autocompose.py", line 295, in <module>
    main()
  File "/usr/src/app/./autocompose.py", line 104, in main
    cfile, c_networks, c_volumes = generate(cname, createvolumes=args.createvolumes)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/./autocompose.py", line 143, in generate
    c = docker.from_env()
        ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/client.py", line 96, in from_env
    return cls(
           ^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/docker-6.0.1-py3.11.egg/docker/api/client.py", line 221, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: HTTPConnection.request() got an unexpected keyword argument 'chunked'

Thats my docker version output:

Client: Docker Engine - Community
 Version:           23.0.5
 API version:       1.42
 Go version:        go1.19.8
 Git commit:        bc4487a
 Built:             Wed Apr 26 16:21:07 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.5
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.8
  Git commit:       94d3ad6
  Built:            Wed Apr 26 16:21:07 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

I am using ubuntu 22.04. Any ideas? Filled my storage full earlier (0% space left on drive) that bricked my docker logs. Dont know if this is relevant. Hope some of you can help me.

That container is not available

Hi, What version of python do you need to run correctly? I receive the following error.

  File "autocompose.py", line 148
    print("That container is not available.", file=sys.stderr)
                                                  ^
SyntaxError: invalid syntax

I use Python 3.8.10 in Ubuntu 20.04.

Any helps?

errore while deploying an autocompose yaml generated file

If i do docker-compose up of a file generated by the autocompose i got this error:

Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in
load_entry_point('docker-compose==1.21.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 71, in main
command()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 124, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 41, in project_from_options
compatibility=options.get('--compatibility'),
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 113, in get_project
config_data = config.load(config_details, compatibility)
File "/usr/lib/python3/dist-packages/compose/config/config.py", line 385, in load
for config_file in config_details.config_files
File "/usr/lib/python3/dist-packages/compose/config/config.py", line 385, in
for config_file in config_details.config_files
File "/usr/lib/python3/dist-packages/compose/config/config.py", line 552, in process_config_file
validate_against_config_schema(config_file)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 437, in validate_against_config_schema
config_file.filename)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 498, in handle_errors
error_msg = '\n'.join(format_error_func(error) for error in errors)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 498, in
error_msg = '\n'.join(format_error_func(error) for error in errors)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 424, in process_config_schema_errors
return handle_generic_error(error, path)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 297, in handle_generic_error
config_key, error_msg = _parse_oneof_validator(error)
File "/usr/lib/python3/dist-packages/compose/config/validation.py", line 385, in _parse_oneof_validator
json.dumps(context.instance),
File "/usr/lib/python3.7/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type datetime is not JSON serializable

Error running this from Docker

I've created a container and try to run this but get the error

usage: autocompose.py [-h] cname
autocompose.py: error: the following arguments are required: cname

My input parameter was

docker run -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $ombi

issue with some entry point

The generated docker-compose.yml file below is not accepted by docker compose

version: "3"
services:
  seafile-memcached:
    container_name: seafile-memcached
    entrypoint:
      - memcached
      - -m
      - 256

I had to group the entry point as below to avoid the error (everything in one line)

services.seafile-memcached.entrypoint.2 must be a string

entrypoint: memcached -m 256

Hope it helps

Multiple networks and alias

I have a container that is attached to two networks: dockerNet and dockerNetv6 (dockerNet is set as the default network of this container). The container has also some aliases.
Unfortunately the tool ignores multiple networks and aliases.

The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7)

When running sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose:latest container1 container2

we're getting the following error

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error

i did a google search but it seems something is missing in the build command,
hope it's a easy fix

date_or_time syntax error?

I am getting this error when running sudo python autocompose.py any container

File "autocompose.py", line 42
def is_date_or_time(s: str):
^
SyntaxError: invalid syntax

Docker Info
Client:
Context: default
Debug Mode: false
Plugins:
compose: Docker Compose (Docker Inc., 2.10.2)

Server:
Containers: 24
Running: 16
Paused: 0
Stopped: 8
Images: 53
Server Version: 20.10.17-ce
Storage Driver: btrfs
Build Version: Btrfs v5.18.1
Library Version: 102
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux oci runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc version: v1.1.4-0-ga916309fff0f
init version:
Security Options:
apparmor
seccomp
Profile: default
cgroupns
Kernel Version: 5.19.7-1-default
Operating System: openSUSE Tumbleweed
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.13GiB
Name: caesar
ID: Y52M:FTLU:T5JM:7RZL:YU3H:QKIG:LLUC:P3M6:JCQQ:HVLX:KFEM:AWCQ
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

RuntimeError: invalid GMT offset

Hi

I am trying to run the autocompose with the docker image. but somehow it comes to an error. does anyone have a hint?


docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose $(docker ps -aq)
Traceback (most recent call last):
File "/usr/src/app/./autocompose.py", line 9, in
import docker
File "/usr/local/lib/python3.12/site-packages/docker-7.0.0-py3.12.egg/docker/init.py", line 1, in
from .api import APIClient
File "/usr/local/lib/python3.12/site-packages/docker-7.0.0-py3.12.egg/docker/api/init.py", line 1, in
from .client import APIClient
File "/usr/local/lib/python3.12/site-packages/docker-7.0.0-py3.12.egg/docker/api/client.py", line 6, in
import requests
File "/usr/local/lib/python3.12/site-packages/requests-2.31.0-py3.12.egg/requests/init.py", line 43, in
import urllib3
File "/usr/local/lib/python3.12/site-packages/urllib3-2.1.0-py3.12.egg/urllib3/init.py", line 8, in
import logging
File "/usr/local/lib/python3.12/logging/init.py", line 26, in
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
RuntimeError: invalid GMT offset

Just a little contribution: shell script to execute docker-autocompose and backup yaml

Just my 2cents on a way to execute docker-autocompose:

#!/bin/bash

# https://github.com/Red5d/docker-autocompose

BACKUP_DIR="/volume1/docker/backupcontainersetup"
EXPORT_DATE="$(date +%Y-%m-%d_%H-%M)"
BACKUP_FILE="${BACKUP_DIR}/docker-autocompose_${EXPORT_DATE}.yaml"

# IncludedContainer=(diun sabnzbd watchtower)
IncludedContainer=($(docker ps -a --format "{{ .Names }}"))

echo "exporting container yaml settings to ${BACKUP_FILE}"
echo ${IncludedContainer[@]}

echo "# docker-compose file generated by Red5d/docker-autocompose" > "${BACKUP_FILE}"
echo "# included containers: ${IncludedContainer[@]}" >> "${BACKUP_FILE}"

# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose:latest ${IncludedContainer[@]}  >> "${BACKUP_FILE}"

# export all containers
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose:latest $(docker ps -aq)  >> "${BACKUP_FILE}"

Block of volumes in random order (mountpoints)

I regularly run the program and send the output to git, and I get too many version changes only because the order of the volumes appears randomly, I think that just adding .sort() on line 250 would be the solution to my problem leaving it as:

values["volumes"] = mountpoints.sort()

image image

Impossible to run on a stoped container

As the title says if a container is not running the auto compose does not work it's for some container configuration impossible to achieve.

is it something that could be changed ?

permission denied issue!

Whenever I run:

$ sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose $(docker ps -aq) >docker-compose.yml

I get this error:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied

What's wrong in my command?!

$ sudo docker ps -aq
e596a3affcb0
c5697eca3917
8e9ef6171f40
8b236c9c7504
fb2847e1f2ab
f58ff2b58975
60453ff5ba63
b11239856898
2233450c6921
bb27a2db8ba3
064156bf6554

Container with network within another container

While tring to get the docker compose of an old container that use the network of another container it gives this error:

Traceback (most recent call last): File "/root/docker-autocompose-master/autocompose.py", line 211, in <module> main() File "/root/docker-autocompose-master/autocompose.py", line 29, in main cfile, c_networks, c_volumes = generate(cname, createvolumes=args.createvolumes) File "/root/docker-autocompose-master/autocompose.py", line 140, in generate assumed_default_network = list(cattrs['NetworkSettings']['Networks'].keys())[0] IndexError: list index out of range

The old docker command for the network was --network=container:2fa4041a6e80a5499dbef6671ba30c2c40d40b70a4280db6d064bf20c43f5c6a

autocompose.py does not use the set context?

How to set this so the docker context setting is used by autocompose.py?

i.e. :
autocompose.py daa012303ed2
That container is not available.

docker ps | grep daa012303ed2
does list it.

No volumes: section. docker-compose: no declaration was found in the volumes section

I had test it for example with portainer.
because there is no volumes section, docker-compose raise an error.
docker-compose: no declaration was found in the volumes section

Output:
version: "3"
services:
portainer:
container_name: portainer
entrypoint:
- /portainer
environment:
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
hostname: 744e2324ef35
image: portainer/portainer-ce
ipc: private
logging:
driver: json-file
options: {}
networks:
- bridge
ports:
- 8000:8000/tcp
- 9000:9000/tcp
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
working_dir: /
networks:
bridge:

Missing in iml file something like this.
volumes:
portainer_data:
external: true

Documentation - container id vs container name

The documentation says to use:
docker run -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose

However, that always failed with:
That container is not running.

The following does work:
docker run -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose

I would suggest updating the docs. Bonus points for updating your code to accept a name OR id.

Doesn't work with python-docker 4.2.0

lemmy@akari:~/Work/susebuildservice/home:lemmy04/python-docker-autocompose/t/docker-autocompose> python3 ./autocompose.py awx_task awx_web
Traceback (most recent call last):
  File "./autocompose.py", line 126, in <module>
    main()
  File "./autocompose.py", line 15, in main
    cfile, networks = generate(cname)
  File "./autocompose.py", line 30, in generate
    c = docker.from_env()
AttributeError: module 'docker' has no attribute 'from_env'

python-docker 2.0.0 is several years old by now, can this be adapted to python-docker 4.2.0?

Backup with a small problem at restore (Host/Network)

Hi,
im not sure that this is a autocompose "problem".
I running a AdGuard Home Container without problems. If i run autocompose against this i will get this

".
.
 network_mode: "host"
-
.

"

if i try to make a docker -d up i get

docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings

I have to remove/edit the line and corect it in portainer after restore.

Docker error while fetching server API version

Script failed with the following exception when tried to get compose yaml from the running container.

$ sudo python3 ./autocompose.py <my container id>
Traceback (most recent call last):
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/api/client.py", line 214, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/api/client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
TypeError: request() got an unexpected keyword argument 'chunked'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./autocompose.py", line 296, in <module>
    main()
  File "./autocompose.py", line 105, in main
    cfile, c_networks, c_volumes = generate(cname, createvolumes=args.createvolumes)
  File "./autocompose.py", line 144, in generate
    c = docker.from_env()
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/client.py", line 96, in from_env
    return cls(
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
  File "/tmp/docker-autocompose/autocompose-venv/lib/python3.8/site-packages/docker/api/client.py", line 221, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: request() got an unexpected keyword argument 'chunked'

Docker version:

$ docker --version
Docker version 25.0.2, build 29cf629

$ docker version
Client: Docker Engine - Community
 Version:           25.0.2
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        29cf629
 Built:             Thu Feb  1 00:23:19 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.2
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       fce6e0c
  Built:            Thu Feb  1 00:23:19 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Packages versions:

$ pip3 freeze
certifi==2024.2.2
charset-normalizer==3.3.2
docker==4.4.4
idna==3.6
pyaml==20.4.0
PyYAML==6.0.1
requests==2.31.0
six==1.16.0
urllib3==2.2.0
websocket-client==1.7.0

Script version:

$ git log -1
commit 2e6a55fad651941d33084d2d37793efc270780da (HEAD -> master, origin/master, origin/HEAD)
Author: Bitals <[email protected]>
Date:   Tue Nov 28 02:08:31 2023 +0000

    Installation instructions and AUR (#68)
    
    I added a bit of information about installing this tool to the system and about my AUR packages.
    
    Also the PyPI version is outdated (1.0.1 from Jan 3 2016, https://pypi.org/project/docker-autocompose/#history), is it still supported?

Probably related to the #60.

unable to start container from yml file

when im trying to start container from exported yml file, im receiving following error message:
root@openmediavault:~/smokeping# docker-compose up -d ERROR: Invalid interpolation format for "environment" option in service "smokeping": "PS1=$(whoami)@$(hostname):$(pwd)\$ "

the environment looks like this:
version: "3"
services:
smokeping:
container_name: smokeping
entrypoint:
- /init
environment:
- PUID=1000
- PGID=100
- TZ=Europe/Bratislava
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- 'PS1=$(whoami)@$(hostname):$(pwd)$ '
- HOME=/root
- TERM=xterm
hostname: 442d8cca9031

/var/run/docker.sock - docker compose issue

docker-autocompose generates a docker-compose.yml that returns an error for docker compose (2.9.0)

volumes:
  /var/run/docker.sock:
    external: true

Removing the 3 lines above from docker-compose.yml fix the issue.

IndexError: list index out of range

Hello, I have an issue when I want print all container :

billou@billou-serveur:~/Téléchargements/Serveur/docker-autocompose$ sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose $(docker ps -aq) Traceback (most recent call last): File "/usr/src/app/./autocompose.py", line 211, in <module> main() File "/usr/src/app/./autocompose.py", line 29, in main cfile, c_networks, c_volumes = generate(cname, createvolumes=args.createvolumes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/app/./autocompose.py", line 140, in generate assumed_default_network = list(cattrs['NetworkSettings']['Networks'].keys())[0] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ IndexError: list index out of range

Any idea please?

The default network adapter "bridge" breaks docker-compose

When I try to import the docker-compose file (after I fix the volume not defined error) it comes back with

"ERROR: for Dokuwiki network-scoped alias is supported only for containers in user defined networks

ERROR: for Dokuwiki network-scoped alias is supported only for containers in user defined networks
ERROR: Encountered errors while bringing up the project."

to fix it, I can change

networks:
  - bridge

to

network_mode: bridge

I know that I'm actually changing the context of the file to say "just bridge my connection" instead of "join the bridge network", but that's all I need for my containers

thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.