Home > other >  how to migrate docker into another machine without cloning the entire machine
how to migrate docker into another machine without cloning the entire machine

Time:11-11

I currently manage my docker for postgresql(timescaleDB) in this way, opening a docker in a screen to run in the background. So that I could always check it with screen.

screen -dmS i2
screen -S i2 -X stuff 'docker run -ti --user 1000:1000  -p 5432:5432 --name timescaledb  --volume=/home/ubuntu/pgdata3:/home/postgresql/pgdata --rm -e POSTGRES_PASSWORD=sdjaisiisiauda123114892u3hihi -e PGDATA=/home/postgresql/pgdata timescale/timescaledb-ha:pg13-latest;\n'

I'm using EC2 as well and i accidentally requested large volume and i wanted to go back to small volume machine. And I already used this database extensive so that I don't want to reconstruct the data in the new machine.

My question: how do i migrate this docker image/snapshot/instance (my term may not be accurate) to another machine and run from the other machine using the same command?

Thanks

CodePudding user response:

You don't need to migrate the docker image- that's what docker is for. You just need to migrate the data.

--volume=/home/ubuntu/pgdata3:/home/postgresql/pgdata

This is the important part- its mapping the data folder from inside the container to /home/ubuntu/pgdata3 on the root filesystem. So- stop your container, zip up that folder, unzip it on the new machine in the same location, and run the docker command from above on the new machine.

Also- you don't really need to use "screen" for this- docker run --detach (instead of -ti) will do the same thing.

If you're on aws and want to make this even easier, you can mount an EBS volume at that location on the new machine before unzipping your data, and in the future you could just attach that volume to a new machine instead of doing the zip/unzip process.

  • Related