3

I've moved my docker-compose container from the development machine to a server using docker save image-name > image-name.tar and cat image-name.tar | docker load. I can see that my image is loaded by running docker images. But when I want to start my server with docker-compose up, it says that there isn't any docker-compose.yml. And there isn't really any .yml file. So how to do with this?

UPDATE When I've copied all my project files to the server (including docker-compose.yml), everything started to work. But is it normal approach and why I needed to save-load image first?

1

1 Answer 1

1

What you achieve with docker save image-name > image-name.tar and cat image-name.tar | docker load is that you put a Docker image into an archive and extract the image on another machine after that. You could check whether this worked correctly with docker run --rm image-name.

An image is just like a blueprint you can use for running containers. This has nothing to do with your docker-compose.yml, which is just a configuration file that has to live somewhere on your machine. You would have to copy this file manually to the remote machine you wish to run your image on, e.g. using scp docker-compose.yml remote_machine:/home/your_user/docker-compose.yml. You could then run docker-compose up from /home/your_user.

EDIT: Additional info concerning the updated question:

UPDATE When I've copied all my project files to the server (including docker-compose.yml), everything started to work. But is it normal approach and why I needed to save-load image first?

Personally, I have never used this approach of transferring a Docker image (but it's cool, didn't know it). What you typically would do is pushing your image to a Docker registry (either the official DockerHub one, or a self-hosted registry) and then pulling it from there.

Sign up to request clarification or add additional context in comments.

4 Comments

But do I still need to copy to remote machine project files?
You need the docker-compose.yml file or whatever other script or artifact you need to launch the image. You should not need your application source code, that should be bundled into the image.
It depends on your project, but it you want to use docker-compose, you definitely need the corresponding *.yml file on the remote machine. If you are using named volumes (e.g. if you need specific files in your container), you would also have to transfer files.
A big plus of docker compose over just docker is to avoid a huge script with docker run commands, among which for example is the loading of an image. In many situations you don't have access to any repository so you need to ship a tar image. This is why it would make sense to let docker-compose load an image instead of having to create a script to first load the image and then call docker-compose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.