boot2docker command works on shell, but not in script

New to docker here. I have a series of commands which, if fire them off on the shell, work just fine, but if I put them in a script, don’t.

boot2docker destroy
boot2docker init
boot2docker start
boot2docker ssh &
host=$(boot2docker ip 2> /dev/null)
# everything works fine up to here
ssh -i $HOME/.ssh/id_boot2docker -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" docker@$host docker run --net=host my-image

If I don’t try to run a command via ssh, everything works. Viz:

  • How to persist changes in boot2docker
  • boot2docker is autoupgrading
  • Vagrant and Docker provider: Container not loaded, Boot2Docker VM not available with SSH
  • How to have bash script answer interactive prompts (no y/n only)?
  • Keep getting Could not read CA certificate when trying to start docker
  • How to create an overlay network with Docker?
  • ssh -i $HOME/.ssh/id_boot2docker -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" docker@$host

    This brings up the docker ssh prompt. But if I do run the command via the script (and this is what I actually need to do) I get the error message:

    level="fatal" msg="Post http:///var/run/docker.sock/v1.16/containers/create: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?"

    Again, if I just enter that last command, or the whole litany of commands, into the shell, no problems. How can I make this script work?

    Thanks

    update
    If I put that last line in its own script, and run the two scripts in sequence from the command line, everything is fine (same as just typing all the commands in sequence.) If I chain the scripts, or create a third to run them in sequence, I get the error. What am I to make of this?

    Thanks

  • Redis Sentinel manual failover command timesout
  • Docker container blocking text/event-stream
  • Can't connect to ASP.Net site in Docker for Windows
  • docker-compose.yml with multiple env_files
  • Docker - one process per container?
  • Docker-machine how to chose IP with virtualbox driver
  • One Solution collect form web for “boot2docker command works on shell, but not in script”

    host probably isn’t defined when you try to use it. You can probably confirm that by echoing it’s value before running ssh. Easiest solution would be to put these two lines together in the same file:

    host=$(boot2docker ip 2> /dev/null)
    ssh -i $HOME/.ssh/id_boot2docker -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" docker@$host docker run --net=host my-image
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.