red5d / docker-autocompose Goto Github PK
View Code? Open in Web Editor NEWGenerate a docker-compose yaml definition from a running container
Generate a docker-compose yaml definition from a running container
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
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,
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.
I'm looking for a feature where you can generate one compose file from all your containers running at once, or would the following work?
docker ps -aq | xargs sudo python autocompose.py
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? :)
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
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 ?
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
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'
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,
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'
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?
should be network_mode: "host" in docker-compose but it gets created like:
networks:
- host
networks:
host:
external: true
name: host
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).
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.
An original container definition that has a shared mount ex: /host/folder:/container/folder:shared
gives an output /host/folder:/container/folder
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.
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?
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
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
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
Is there or could there be a way to export the docker compose for all containers without having to name each one?
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.
Is there a linux/arm/v8 version yet? If not, no problem! I can manually copy the stacks ^^
Just wondering if I am doing something wrong!
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
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
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
Some of my volumes are mounted via CIFS. Having a command switch to output volumes so it's listed like below allows for better migrations would be superb.
volumes:
cifs_mount:
driver: local
driver_opts:
type: cifs
device: //<REMOTE_IP>/<PATH_TO_LIBRARY>
o: "username=,password=,vers=3.0,uid=,gid="
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}"
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 ?
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
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
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.
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
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.
Hello I have some static IPs set for various containers and for some reason it isn't saving those fields.
It'd be kind of useful if there was an all
argument one could pass instead of individual container names. Would be a little bit of a time saver where we use this to help support people w/ Docker issues. :)
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?
Terribly sorry, wrong github page.
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.
Neat tool! Would be nice to have an automated build on DockerHub.
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.
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
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.
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?
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.