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:

  • Running a bash script before startup in an NGINX docker container
  • Start up script fails with error “-e: invalid option”, what is missing?
  • Can't connect to docker process
  • Dockerfile - How to pass an answer to a prompt post apt-get install?
  • Docker toolbox volumes on windows doesn't refresh changes on container
  • Bidirectional communication with 'docker exec -it bash <container_id>' using docker-py
  • 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?


    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?


  • How to build boot2docker.iso from source?
  • Docker not starting with docker start command in 1.3
  • How to configure the docker file to run cgi-script like perl
  • Configure PM2 module with linked docker container
  • line 113: conf/neo4j.conf: Permission denied
  • pkgProblemResolver::Resolve generated breaks, this may be caused by held packages
  • 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.