 						env[envVar.name] = envVar.value
 				return {
 					imageId: "#{process.env.REGISTRY_ENDPOINT}/#{path.basename(app.git_repository, '.git')}/#{app.commit}"
-					env: env
+					env: JSON.stringify(env) # The env has to be stored as a JSON string for knex
 				}
 
 			remoteApps = _.indexBy(remoteApps, 'imageId')

			Cmd: ['/bin/bash', '-c', '/start']
			Volumes:
				'/dev': {}
			Env: _.map app.env, (v, k) -> k + '=' + v
			ExposedPorts: ports
		)
		.then (container) ->

	.then ->
		console.log("Creating container:", app.imageId)
		ports = {}
		# Parse the env vars before trying to access them, that's because they have to be stringified for knex..
		env = JSON.parse(app.env)
		if env.PORT?
			maybePort = parseInt(env.PORT, 10)
			if parseFloat(env.PORT) is maybePort and maybePort > 0 and maybePort < 65535
				port = maybePort
		if port?
			ports[port + '/tcp'] = {}
