Docker Autocompose

Currently reading
Docker Autocompose

A user of the german Synology forum posted a bash snippet, which some of you mind find useful:
It will automaticly create a {container_name}-compose.yml per docker container, preconfigured with all settings the container had:
Code:
while read -r container_name; do
  docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose ${container_name} > ${container_name}-compose.yml
done <<< "$(docker ps --format '{{.Names}}')"


Of course the red5d/docker-autocompose can be used for a standalone container as well:
Code:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $(docker ps -q --filter name=plex) > docker-compose.yml

Feel free to replace $(docker ps -q --filter name=plex) with a container name or id of your own choice.

What a nugget :)
 
I have no experience with Docker Compose yet, but this sounds like a very easy method to have to fire up running containers again just like before, right?

In my situation with the combination of NordVPN and privoxy containers they do not start properly after a NAS reboot. That is because the NordVPN proxy container needs to be started up properly before the privoxy containers does. I guess with a Docker Compose files scheduled in task manager it should be eazier to tailor-made the automation of it?

1604527463314.png
 
Last edited:
Looks good to me :)

docker-compose will add a "project name" as a prefix to all it's objects (containers without "containername:), volumes, networks), which defaults to the directory name. Onthe top of my head, I am unsure if the directory name relates to the directory you execute the docker-compose command in, or the directory the docker-compose.yml is located in.

Just add docker-compose --file /path/to/you/compose.yml up -d for each compose yml you want to fire up.

I have just checked, it will add the old container name to the compose configuration, it will remain unchainged regardless of the project name.
 
Thanks for this, for some reason I couldn't get this working so went with this one instead


with this command and replacing the last part with the name of the container. you then copy and paste the output into a file

sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock gerkiz/autocompose homeassistant
 
I've tried code this but nothing happens. I'm guessing their should be a generated file somewhere?
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $(docker ps -q --filter name=portainer_agent) > docker-compose.yml

And If I use this code:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose portainer_agent

I get this output in terminal:
Code:
version: "3"
services:
  portainer_agent:
    container_name: portainer_agent
    entrypoint:
      - ./agent
    environment:
      - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    hostname: portainer_agent
    image: portainer/agent:latest
    ipc: shareable
    logging:
      driver: db
      options: {}
    mac_address: 02:42:ac:11:00:05
    networks:
      bridge:
        aliases:
    ports:
      - 9001:9001/tcp
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    working_dir: /app
networks:
  bridge:
    external: true
 
Found it the file are safe in the root folder!
Can it be configured to safe the file somewhere else? Somewhere I can easily access the files?
Or Am I doing something wrong?
 
I get this output in terminal
You can copy/paste that output to a plain text editor and save it as "portainer.yml" (or whatever name you choose). Or...

I'm guessing their should be a generated file somewhere?
You should see a file "docker-compose.yml" ... that is the file you are looking for. Then

Code:
mv docker-compose.yml /volume1/path/you/desire/portainer.yml
 
You can copy/paste that output to a plain text editor and save it as "portainer.yml" (or whatever name you choose). Or...


You should see a file "docker-compose.yml" ... that is the file you are looking for. Then

Code:
mv docker-compose.yml /volume1/path/you/desire/portainer.yml
Thanks for the tip!
 
That's one way. Though, you can already use the target path after the > symbol. I called the file docker-compose.yml, which gets written in the current(!) directory. Instead you could have used a different filename or an absolut path like /volume1/docker/portainer.yml.

You can specify alternative filenames with docker compose with the -f parameter.
-- post merged: --

Found it the file are safe in the root folder!
More precisly the file has been saved in the current folder, which just used to be the root folder in your case. If you'd been in a different folder, the file would've been created there.
 
I found that this is good to get you started but the output generally requires quite a bit of cleaning up. Once you have figured it out doing updates is so easy now.
What do you mean by cleaning up?
-- post merged: --

That's one way. Though, you can already use the target path after the > symbol. I called the file docker-compose.yml, which gets written in the current(!) directory. Instead you could have used a different filename or an absolut path like /volume1/docker/portainer.yml.

You can specify alternative filenames with docker compose with the -f parameter.
-- post merged: --


More precisly the file has been saved in the current folder, which just used to be the root folder in your case. If you'd been in a different folder, the file would've been created there.
Been experimenting a bit:
Code:
FOLDER=portainer_agent
CONTAINER_NAME=portainer_agent
DIR=/volume1/docker/$FOLDER/
FILE=$DIR$CONTAINER_NAME-compose.yml
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $(docker ps -q --filter name=$CONTAINER_NAME) > $FILE
 
The output tends to
What do you mean by cleaning up?
-- post merged: --


Been experimenting a bit:
Code:
FOLDER=portainer_agent
CONTAINER_NAME=portainer_agent
DIR=/volume1/docker/$FOLDER/
FILE=$DIR$CONTAINER_NAME-compose.yml
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $(docker ps -q --filter name=$CONTAINER_NAME) > $FILE
I found that the output contained a lot of additional environment variables that were not required for the docker compose file as were automatically added based on the current version of the container you bring up. (I never added them to the syno GUI)

I cleaned up all the outputs down to a single docker compose file in my docker share for all my containers and made them all formatted in the same consistent way, for example Radarr

YAML:
  linuxserver-radarr:
    image: linuxserver/radarr:latest
    container_name: radarr-linuxserver
    environment:
      - PGID=100
      - PUID=1031
      - TZ=Europe/London
    volumes:
      - /volume1/movies:/movies
      - /volume1/movies chinese:/movies chinese
      - /volume1/movies kids:/movies kids
      - /volume1/docker/radarr:/config
      - /volumeUSB3/usbshare:/downloads
    ports:
      - 7878:7878/tcp
    restart: unless-stopped


so now I just run the following and do a complete update as all configs are in a single docker-compose.yml

Code:
cd /volume1/docker/
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose up -d --remove-orphans

or if I am just updating a single container you could stick each compose into its own file, rarely bother with this as its quicker just to update everything.

Code:
sudo docker-compose -f /volume1/docker/dockercompose/minecraftspigot.yml up -d
 
Thanks for the detailed explanation. I am not very familiar with compose yet, but thanks to Autocompose and your explanation I am starting to get it. I will study compose further and test it. For now I am still using CLi to create my containers and in combination with cronjob to update them.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

I can’t find any option to restore just the settings. 1710356648 Phew, managed to fix it. Within the...
Replies
4
Views
390
Good to hear. Deluge has not been updated for almost two years now as an app, nevertheless. But it gives...
Replies
12
Views
960
  • Question
Open an issue on that GitHub page. The developers will be glad to assist. OP has posted two threads on...
Replies
5
Views
963
I'm happy with email notifications but in v0.3.3 of dockcheck the author added apprise notifications...
Replies
4
Views
1,041
I am also trying to setup a Z-wave USB dongle and am getting stuck after following the same steps as...
Replies
1
Views
1,030
How did you create the Portainer container in first place? As in exact docker run commands or in case...
Replies
7
Views
1,240
Looks like I triggered you somehow with my post: it was not my intention. I have no idea whether bash or...
Replies
4
Views
1,534

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top