 	maybePort = parseInt(port, 10)
 	return parseFloat(port) is maybePort and maybePort > 0 and maybePort < 65535
 
+fetch = (app) ->
+	docker.getImage(app.imageId).inspectAsync()
+	.catch (error) ->
+		utils.mixpanelTrack('Application download', app)
+		logSystemEvent('Downloading application ' + app.imageId)
+		updateDeviceInfo(status: 'Downloading')
+		dockerUtils.fetchImageWithProgress app.imageId, (progress) ->
+			updateDeviceInfo(download_progress: progress.percentage)
+		.then ->
+			docker.getImage(app.imageId).inspectAsync()
+
 exports.start = start = (app) ->
 	Promise.try ->
 		# Parse the env vars before trying to access them, that's because they have to be stringified for knex..

			else
				knex('app').insert(app)
		.tap (container) ->
			console.log('Starting container:', app.imageId)
			ports = {}
			if portList?
				portList.forEach (port) ->


		# If there is no existing container then create one instead.
		containerPromise.catch ->
			fetch(app)
			.then (imageInfo) ->
				utils.mixpanelTrack('Application install', app)
				logSystemEvent('Installing application ' + app.imageId)
				updateDeviceInfo(status: 'Installing')

				ports = {}
				if portList?
					portList.forEach (port) ->
