Beispiel #1
0
    def post(self):
        """Creates a new container based on a POST to /containers."""
        self.reqparse.add_argument(
            'image', type=str, required=True, help='Image cannot be blank')
        args = self.reqparse.parse_args()

        # Check that image exists
        try:
            image = client.inspect_image(args['image'])
        except APIError:
            abort(500, message="Image %s not found on this server" %
                  args['image'])

        if not image['container_config']['ExposedPorts']:
            abort(500, message="This image does not expose any ports. \
                Use the EXPOSE command in your dockerfile to specify some.")

        # Create and start the container
        try:
            result = client.create_container(image=args['image'],
                                             detach=True,
                                             )
            container_id = result['Id']
            container = start_container(container_id)
        except APIError as exception:
            abort(500, message=exception.explanation)

        return marshal(container, container_fields), 201
Beispiel #2
0
    def patch(self, container_id):
        """Updates information on a single container. Currently just status."""
        args = self.reqparse.parse_args()

        if 'status' in args:
            if args['status'] == STOPPED:
                stop_container.delay(container_id)
                r.hset('containers:%s' % container_id, 'status', STOPPING)
            elif args['status'] == RUNNING:
                try:
                    start_container(container_id)
                except APIError as exception:
                    abort(500, message=exception.explanation)

        container = r.hgetall('containers:%s' % container_id)
        return marshal(container, container_fields)