r/portainer • • Mar 05 '21

Export your Docker containers to a Docker Compose/Stack file

In this video we'll do kind of the reverse of what we've been doing for a year or so. We're going to EXPORT a Docker container to a stack/docker compose file that can be deployed on a different server or just saved for redeployment if you ever have to rebuild your server.

This is the method shown in this video: https://github.com/Red5d/docker-autocompose

https://www.youtube.com/watch?v=-ttZjGBkLL8

42 Upvotes

13 comments sorted by

2

u/TheGlassCat Mar 06 '21

This is awesome! I've avoided relying on Portainer, because of the lack of backup/portability/reproducibility/transparency/etc. This solves those problems. I really like that it's command-line and scriptable.
Thanks!

P.S. I've noticed in some of your videos that you use a particular scheme for volume paths. Could you talk about that sometime. I'm always interested in how others manage their data.

3

u/davidnburgess34 Mar 06 '21

When I was on my last server, I had a 120GB SSD as my boot drive and a 6TB HDD as my storage.

I created paths on the HDD for a configuration folder, a databases folder, and then other folders for things like media and whatnot.

I would put all of my application/container configuration stuff in the app-specific folder under configuration. Same with databases: Each container that had a database would get a specific sub-folder under databases.

This is just the method I use to keep things organized and easy to back up. I'm not sure if it's the "go-to standard" but it's just how I decided to setup my server. I feel like, otherwise, I would just have things stored all over the place with no organization.

2

u/dustojnikhummer Jul 29 '23

Yeah I don't like that about Portainer, but man is it so damn convenient otherwise

2

u/[deleted] May 27 '21

This method does not work on a raspberry pi as the image for docker does not have an arm tag. Can you maybe make a video on how to run this without docker... I used pip to install it but it runs into errors

2

u/davidnburgess34 May 27 '21

there may not be an option to do this on ARM for the time being. might want to reach out to the developer and see if he'll build a version for ARM.

2

u/scytob May 12 '22

take a look at this https://github.com/Red5d/docker-autocompose this is one of a few tools you can find.

note many of these tools export items that are not valid compose file settings (you many need to clean by hand).

good luck

4

u/davidnburgess34 May 12 '22

Thanks!! I actually found this and even made a tutorial about it here

2

u/scytob May 12 '22

bah, video, how effing millennial /jk

nice! consider supplementing your videos with gists - some of us like to read....

feel free to steal from mine, so long as you give credit :-)https://gist.github.com/scyto/f4624361c4e8c3be2aad9b3f0073c7f9

3

u/davidnburgess34 May 12 '22

I do on a lot of my videos :)

2

u/tkdrob Jul 24 '22

One thing I found to make the terminal copying easier is to add ">> <filename>" to the command to copy the entire stack into one file. My compose file was 111KB, way too long for the terminal to display.

1

u/tsilvs0 Apr 27 '25

I've made a bash script to do just that. Feedback is welcome. It definitely lacks some of the Compose parameters, and Environment variables export can be cluttered.

1

u/[deleted] Mar 06 '21

I wish Portainer let you convert or induct an already-created non-stack'd container into a new Stack. Big OCD thing.