23
How hard is it to move Docker containers to another system?
(lemmy.dbzer0.com)
A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.
Beginning of January 1st 2024 this rule WILL be enforced. Posts that are not tagged will be warned and if not fixed within 24h then removed!
The data that your software interacts with is external to a container but can be mapped to the container file system so that the software can interact with it. For example, your Minecraft server relies on disk files consisting of the world state and server config files (and plugins if you have any). These will still be on your host system, not inside the container. In order to transfer this to another system, you have to take those files from your host and move them to the new host. Then copy your docker config files over too so you can start a new container that points to your files on disk and it should function the same as it did before, but possibly with a different IP address.
An easy way to think of it is that a container can be restarted, like maybe when you restart the PC. When a container is restarted, all the files in the container reset to their initial state. If you go into a container and create files then restart the container, those files will be gone. Any data that needs to be persisted between restarts needs to go on your host filesystem and volume mount it to the container.
Thanks for replying :)
I think I'm starting to understand it a bit better. Your first paragraph explains what I thought a Docker container would be like, except that I wasn't sure whether the Minecraft server would be part of the container or not. I always thought of containers as like a mini OS that just runs the required software, and connects to data outside of the container. This is why I thought they could be moved, like a virtual machine can be moved.
Would I be right in thinking that as long as the config is saved externally, the container can be rebuilt on any system with that config file? If so, that's probably exactly what I need.
My data is currently on separate drives to the OS, so my plan is to replace the installed software, e.g. Radarr, with a containerised version so that everything is in containers where possible, then replace the OS with something more suitable. When the computer eventually gets replaced, I want to be able to start up the containers and be ready to go without having to set up all the software again.
Yes that's correct. And containers are not really portable in the way you described. They do have a mini OS in them but the state is not saved when they are "offline". So you can think of it as more of a template, called an image. You can save the image to a file, and move that to a new pc and load that back into Docker, but that's usually unnecessary. As long as you have Internet, you just need to know the name of the image and Docker will just download it if it doesn't already have it. For most popular programs, you'll find an image for it already created so just follow the instructions on what settings to use for things like volume mounts and environment variables. This configuration of variables can be saved into a Docker Compose file for easy reuse instead of typing really long command line to run your container. This Compose file is all you really need to move to the other PC and it'll just download your image and run everything as before.
Oh, that's even easier than I thought then :)
I've got a great internet connection, so as long as I save the Compose files, I can rebuild the image forever, barring changes to the program in the container then. Much easier :D