Skip to content

Instantly share code, notes, and snippets.

@usmanismail
Created March 6, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usmanismail/13ae94d8b9e860058bb5 to your computer and use it in GitHub Desktop.
Save usmanismail/13ae94d8b9e860058bb5 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage(){
echo "Usage: $0 RANCHER_SERVER CONTAINER_NAME IMAGE COMPUTE_NODE"
echo "e.g. $0 my-rancher.com MyContainer ubuntu 1h2"
exit 1
}
# call usage() function if filename not supplied
[[ $# -ne 4 ]] && usage
RANCHER_SERVER=$1
CONTAINER_NAME=$2
IMAGE=$3
COMPUTE_NODE=$4
cat <<EOF > /tmp/data
{
"startOnCreate": true,
"publishAllPorts": false,
"privileged": false,
"stdinOpen": true,
"tty": true,
"commandArgs": [],
"networkIds": [
"1n2"
],
"environment": { },
"requestedHostId": "${COMPUTE_NODE}",
"dataVolumes": [
"/OUTSIDE_CONTAINER:/INSIDE_CONTAINER"
],
"dataVolumesFrom": [],
"dns": [],
"dnsSearch": [],
"capAdd": [],
"capDrop": [],
"lxcConf": {},
"devices": [],
"imageUuid": "docker:${IMAGE}",
"restartPolicy": {
"name": "no"
},
"name": "${CONTAINER_NAME}",
"ports": [
"8080:8080/tcp"
],
"instanceLinks": {}
}
EOF
curl -u "${API_KEY}:${API_SECRET}" -X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data @/tmp/data \
'http://${RANCHER_SERVER}:8080/v1/container'
rm -rf /tmp/data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment