Beispiel #1
0
func (s *Service) recreate(ctx context.Context, c *container.Container) (*container.Container, error) {
	name := c.Name()
	id, _ := c.ID()
	newName := fmt.Sprintf("%s_%s", name, id[:12])
	logrus.Debugf("Renaming %s => %s", name, newName)
	if err := c.Rename(ctx, newName); err != nil {
		logrus.Errorf("Failed to rename old container %s", c.Name())
		return nil, err
	}
	namer := NewSingleNamer(name)
	newContainer, err := s.createContainer(ctx, namer, id, nil, false)
	if err != nil {
		return nil, err
	}
	newID, _ := newContainer.ID()
	logrus.Debugf("Created replacement container %s", newID)
	if err := c.Remove(ctx, false); err != nil {
		logrus.Errorf("Failed to remove old container %s", c.Name())
		return nil, err
	}
	logrus.Debugf("Removed old container %s %s", c.Name(), id)
	return newContainer, nil
}