Home > Mobile >  Dockerfile save image to ssh host
Dockerfile save image to ssh host

Time:07-27

I'm trying to deploy a docker image that is an asp.net core (.NET6) WebApi to ssh server.

I know the command for transferring the image file is:

docker save <my_image_namee> | ssh -C user@address docker load

Is it possible to execute this command within the Dockerfile right after building the image?

CodePudding user response:

A Dockerfile can never run commands on the host, push its own image, save its output to a file, or anything else. The only thing it's possible to do in a Dockerfile is specify the commands needed to build the image within its isolated environment.

So, for example, in your Dockerfile you can't specify the image name that will be used (or its tag), or forcibly push something to a registry, or the complex docker save | ssh sequence you show. There's no option in the Dockerfile to do it.

You must run this as two separate commands using pretty much the syntax you show as your second command. If the two systems are on a shared network, a better approach would be to set up a registry server of some sort and docker push the image there; the docker save...docker load sequence isn't usually a preferred option, unless the two systems are on physically isolated networks. Whatever you need to do after you build the image, you could also consider asking your continuous-integration system to do it for you to avoid the manual step.

CodePudding user response:

No, you cannot include a command in the dockerfile that uploads the image somewhere.

You can, however, create a shell script that builds the image and uploads it. For example:

docker build --tag myimage
docker save myimage | ssh -C user@address docker load

Then you can run this to build and upload the image: bash script.sh.

  • Related