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:

  • Ports not accessible in Docker on Mac
  • when mounting a host directory -v option. Are the mounts available by the time the ENTRYPOINT starts?
  • Docker data container, boot2docker, and the local file system
  • BigTable docker image startup issue: util.NativeCodeLoader: Unable to load native-hadoop library for your platform
  • Access jboss 8080 port inside docker container
  • Can't set docker-machine environment variables bash
  • 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

  • Clone server to docker image
  • Docker run syntax
  • How to Add Docker to Django + Gunicorn + Nginx + Fabric
  • Docker mysql host not privileged
  • Docker container's /proc/<pid>/stat not updating CPU stats
  • How to set PGOPTIONS when starting Postgres using docker-compose
  • 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.