1

I'm working on a Node/Mongo project in Docker and I'm having some trouble starting it in a certain way.

docker image ls

REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE

projectName          latest              4adabfbf53f9        16 minutes ago      2.99GB

mongo                latest              a0f922b3f0a1        4 days ago          366MB

node                 latest              aa3e171e4e95        2 weeks ago         673MB

I'd like to be able to save these images to a tar file and load them onto another machine. Once they're loaded, running docker-compose up fails with an error about not being able to find a config file.

Is there a way save/load Docker images like this?

kreaves
  • 13
  • 1
  • 3
  • Possible duplicate of [The best way to create docker image "offline installer"](https://stackoverflow.com/questions/46560026/the-best-way-to-create-docker-image-offline-installer) – Stefan Crain Apr 24 '18 at 15:52
  • Can you provide the error as the way you are trying is a the correct way. Please remember to use the same image with the same tag in the docker-compose.yml file – Shubhanshu Rastogi Dec 20 '19 at 06:17

1 Answers1

1

One of the core principles of docker is that the containers should be the same if you remove and start them again. Data that you wish to persist can be stored in separate docker volumes or even on a mounted volume which resides on your disk.

If you have a Dockerfile, can you not just move that to the other computer and build it there, or even use a docker registry like docker hub to store the pre-built image? That's the standard way of doing it.

With that said, it is possible to make changes to a container then commit them to the image so that the image itself is updated. Or you can dump the container directly to a tarball with the export command, but I'm not sure this is actually what you need.

Jite
  • 5,761
  • 2
  • 23
  • 37
  • Ideally we'd like to move the images around on a net mount or flash drive, it's a government project so they're a bit iffy about hosting things online. I've managed to get this to work with moving around a tar of the whole project and building it, I'll look into export and see if that will work. – kreaves Apr 24 '18 at 15:05
  • I see... But are the images filled with secrets or only the data in the containers? The images are just built versions of the dockerfile instructions, would not a dockerfile be sufficient enough in that case? Data could be stored on a bind-mount which you could pass over a network or whatever the needs are :) – Jite Apr 24 '18 at 15:08
  • To be sure I understand what you're saying, the docker images only contain instructions to build/run the application and not the actual source code for the application. If that's the case, just dropping the image.tar on another machine and trying to run it won't work. Does that sound about right? – kreaves Apr 24 '18 at 15:19
  • No, the file is the instructions to build the image. When the image is built, you can start a container using the image as the "base" so to speak. So tar'ing the container makes it possible to move and import to another computer with docker. But I haven't really seen a case where that's the best approach. :) – Jite Apr 24 '18 at 15:45
  • I wrote a couple of blog posts about docker which you could read if you want, i hope they help! :) https://jite.eu/2017/9/1/docker-intro/ – Jite Apr 24 '18 at 15:47
  • Thanks, I'll look into that. – kreaves Apr 24 '18 at 16:44