0

I'd like to deploy a container that I've built locally on a DigitalOcean droplet. I've been following these instructions. The problem is that by running:

eval $(docker-machine env DROPLET_NAME)

Docker sets the environment variables to be the remote machine, effectively changing the environment to running Docker on the remote machine. This is expected. However, say I have a local image I've built named rb612/docker-img:latest that I haven't pushed up to a remote. I want to run this in the remote machine context.

If I run:

docker run -d -p 80:8000 rb612/docker-img:latest

Then I get Unable to find image 'rb612/docker-img:latest' locally. If my understand is correct, this is because it's no longer running in the context of my machine. Opening a new shell and running the same command works fine without the remote environment variables set.

So I'm wondering if there's a way I can run this local image on my remote machine. I tried using the -w flag to pass in the local path but I got the same error. Deploying instead with a remote docker image works fine.

rb612
  • 5,280
  • 3
  • 30
  • 68

1 Answers1

1

So I'm wondering if there's a way I can run this local image on my remote machine.

Sure.

You have a couple of options.

Using docker image save/load

  1. You can use docker image save to save the image to a file. Do this either before you run your eval statement, or do it in a different terminal window that doesn't have the remote Docker environment configured:

    docker image save rb612/docker-img:latest > docker-img.tar
    
  2. After running your eval $(...) command, use docker image load to send the image to your remote Docker:

    docker image load < docker-img.tar
    

Now the image is available on your remote Docker host and you can docker run it normally.

Set up a remote registry

You can set up your own remote registry, in which case you can simply docker push to that registry from your local machine and docker pull from the remote machine. This is generally the best long-term solution, but the initial set up (especially securing things properly with SSL) is a little bit more involved. Details are in the documentation.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • This is awesome! Thanks so much. Works like a charm. Just out of curiosity, I was also attempting to do it this way: https://stackoverflow.com/a/23938978/3813411 by copying the `.tar` image to the remote at path `/home/test.tar` using `docker-machine scp` but I wasn't able to load by doing `docker load -i my_machine_name:/home/test.tar`. It also couldn't find it by doing `docker load -i /home/test.tar` either. Was I doing something wrong? It didn't seem like I could specify a path in the remote machine. – rb612 Apr 23 '19 at 00:04