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 :)
 

Shadow

Subscriber
689
246
NAS
DS216+II, DS118, DS718+
Router
  1. RT2600ac
  2. MR2200ac
Operating system
  1. Windows
Mobile operating system
  1. Android
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.
 
30
16
drfrankenstein.co.uk
NAS
1815+, Intel NUC NUC6CAYS Xpenology DSM 6.2.3
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
 
163
40
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
 
163
40
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?
 

Telos

Subscriber
1,721
574
NAS
DS418play, DS213j, DS3622+, DSM 7.1.4-11091
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
 
163
40
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.
 
163
40
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
 
30
16
drfrankenstein.co.uk
NAS
1815+, Intel NUC NUC6CAYS Xpenology DSM 6.2.3
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
 
163
40
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'm a fan of Duplicacy for backups, as it is robust and well-supported and has an active forum. While it...
Replies
0
Views
110
  • Solved
docker0 is the default gateway for the subnet 172.17.0.0/16 and has the ip 172.17.0.1 (see: ip addr show...
Replies
4
Views
225
I want to be able to deploy Docker containers on a seperate Ubuntu VM I have running on my DS718+ . But I...
Replies
0
Views
142

Welcome to SynoForum.com!

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

Registration is free, easy and fast!

Trending threads

Top